bdrv_flush error handling
PATCH 1/1 bdrv_flush error handling
bdrv_flush is declared to return void, but this is wrong because it means that the implementations have nowhere to report their errors. Indeed, the implementations generally ignore errors.
This patch corrects this by making it return int (implicitly, either 0 or -errno, as for other similar functions). All of the implementations and callers are adjusted too.
While looking at this I was surprised to see this:
static void scsi_write_complete(void * opaque, int ret)
...
if (ret) {
fprintf(stderr, "scsi-disc: IO write error\n");
exit(1);
}Surely that is overkill ?
Also, in block-raw-posix.c, raw_pwrite et al seem to return -1 on error (the return value from write) whereas the other block read/write methods return errno values. This is a mistake, surely ? -1 would be -EPERM. If any of the callers did anything with these return values you'd get incorrect error indications.
Finally, it would perhaps be best if the block device emulators wrote to the qemu console to complain if they give write errors. Otherwise the errno value and other important information will be lost, which makes debugging hard.
Thanks,
Ian.
block-qcow.c +2 -2
@@ -879,10 +879,10 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,return 0 ; } -static void qcow_flush (BlockDriverState *bs) +static int qcow_flush (BlockDriverState *bs) {BDRVQcowState *s = bs->opaque; -bdrv_flush (s->hd); +return bdrv_flush (s->hd); }static int qcow_get_info (BlockDriverState *bs,BlockDriverInfo *bdi)
block-qcow2.c +2 -2
@@ -1228,10 +1228,10 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,return 0 ; } -static void qcow_flush (BlockDriverState *bs) +static int qcow_flush (BlockDriverState *bs) {BDRVQcowState *s = bs->opaque; -bdrv_flush (s->hd); +return bdrv_flush (s->hd); }static int qcow_get_info (BlockDriverState *bs,BlockDriverInfo *bdi)
block-raw-posix.c +4 -2
@@ -539,10 +539,12 @@ static int raw_create(const char *filename, int64_t total_size,return 0 ; } -static void raw_flush (BlockDriverState *bs) +static int raw_flush (BlockDriverState *bs) {BDRVRawState *s = bs->opaque; -fsync (s->fd); +if (fsync (s->fd)) +return errno; +return 0 ; }BlockDriver bdrv_raw = {
block-raw-win32.c +6 -2
@@ -269,10 +269,14 @@ static void raw_aio_cancel(BlockDriverAIOCB *blockacb) }#endif /* #if 0 */ -static void raw_flush (BlockDriverState *bs) +static int raw_flush (BlockDriverState *bs) {BDRVRawState *s = bs->opaque; -FlushFileBuffers (s->hfile); +int ret; + ret =FlushFileBuffers (s->hfile); +if (ret) +return -EIO ; +return 0 ; }static void raw_close (BlockDriverState *bs)
block-vmdk.c +2 -2
@@ -815,10 +815,10 @@ static void vmdk_close(BlockDriverState *bs)vmdk_parent_close (s->hd); } -static void vmdk_flush (BlockDriverState *bs) +static int vmdk_flush (BlockDriverState *bs) {BDRVVmdkState *s = bs->opaque; -bdrv_flush (s->hd); +return bdrv_flush (s->hd); }BlockDriver bdrv_vmdk = {
block.c +7 -5
@@ -865,12 +865,14 @@ const char *bdrv_get_device_name(BlockDriverState *bs)return bs->device_name; } -void bdrv_flush (BlockDriverState *bs) +int bdrv_flush (BlockDriverState *bs) { -if (bs->drv->bdrv_flush) - bs->drv->bdrv_flush (bs); -if (bs->backing_hd) -bdrv_flush (bs->backing_hd); +int ret =0 ; +if (bs->drv->bdrv_flush) + ret = bs->drv->bdrv_flush (bs); +if (!ret && bs->backing_hd) + ret =bdrv_flush (bs->backing_hd); +return ret; }#ifndef QEMU_IMG
block.h +1 -1
@@ -98,7 +98,7 @@ void qemu_aio_wait_end(void);int qemu_key_check (BlockDriverState *bs,const char *name);/* Ensure contents are flushed to disk. */ -void bdrv_flush (BlockDriverState *bs); +int bdrv_flush (BlockDriverState *bs);#define BDRV_TYPE_HD 0#define BDRV_TYPE_CDROM 1
block_int.h +1 -1
@@ -42,7 +42,7 @@ struct BlockDriver {void (*bdrv_close)(BlockDriverState *bs);int (*bdrv_create)(const char *filename,int64_t total_sectors,const char *backing_file,int flags); -void (*bdrv_flush)(BlockDriverState *bs); +int (*bdrv_flush)(BlockDriverState *bs);int (*bdrv_is_allocated)(BlockDriverState *bs,int64_t sector_num,int nb_sectors,int *pnum);int (*bdrv_set_key)(BlockDriverState *bs,const char *key);
hw/ide.c +5 -2
@@ -1895,6 +1895,7 @@ static void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)IDEState *s;int unit, n;int lba48 =0 ; +int ret;#ifdef DEBUG_IDE printf ("IDE: write addr=0x%x val=0x%02x\n" , addr, val);
@@ -2140,8 +2141,10 @@ static void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)break ;case WIN_FLUSH_CACHE :case WIN_FLUSH_CACHE_EXT : -if (s->bs) -bdrv_flush (s->bs); +if (s->bs) { + ret =bdrv_flush (s->bs); +if (ret) goto abort_cmd; + } s->status =READY_STAT ;ide_set_irq (s);break ;
hw/scsi-disk.c +7 -1
@@ -293,6 +293,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,uint8_t command;uint8_t *outbuf;SCSIRequest *r; +int ret; command = buf[0 ]; r =scsi_find_request (s, tag);
@@ -620,7 +621,12 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,break ;case 0x35 :DPRINTF ("Synchronise cache (sector %d, count %d)\n" , lba, len); -bdrv_flush (s->bdrv); + ret =bdrv_flush (s->bdrv); +if (ret) { +DPRINTF ("IO error on bdrv_flush\n" ); +scsi_command_complete (r,SENSE_HARDWARE_ERROR ); +return 0 ; + }break ;case 0x43 : {
On Wed, Feb 20, 2008 at 03:53:46PM +0000, Ian Jackson wrote:
Content-Description: message body text
Quoted 11 lines
bdrv_flushis declared to return void, but this is wrong because it means that the implementations have nowhere to report their errors. Indeed, the implementations generally ignore errors.This patch corrects this by making it return int (implicitly, either 0 or -errno, as for other similar functions). All of the implementations and callers are adjusted too.
While looking at this I was surprised to see this:
Quoted 8 lines
static void scsi_write_complete(void * opaque, int ret) ... if (ret) { fprintf(stderr, "scsi-disc: IO write error\n"); exit(1); }Surely that is overkill ?
Yes, any i/o errors I'd expect to be propagated back up to the guest OS as the most appropriate IDE / SCSI error code.
Quoted 11 lines
Also, in
block-raw-posix.c,raw_pwriteet al seem to return -1 on error (the return value from write) whereas the other block read/write methods return errno values. This is a mistake, surely ? -1 would be-EPERM. If any of the callers did anything with these return values you'd get incorrect error indications.Finally, it would perhaps be best if the block device emulators wrote to the qemu console to complain if they give write errors. Otherwise the errno value and other important information will be lost, which makes debugging hard.
If by 'qemu console' you mean stderr, then fine, but please don't spew log messages to the monitor console, because that'll make it very hard to interact with reliably from management tools.
Dan.
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
Daniel P. Berrange writes ("Re: [Qemu-devel] [PATCH] bdrv_flush error handling"):
Quoted 9 lines · Ian Jackson
Quoted 4 lines
Finally, it would perhaps be best if the block device emulators wrote to the qemu console to complain if they give write errors. Otherwise the errno value and other important information will be lost, which makes debugging hard.
If by 'qemu console' you mean stderr, then fine, but please don't spew log messages to the monitor console, because that'll make it very hard to interact with reliably from management tools.
Is it permitted, then, to generally print to qemu's stderr from inside a device model ? This seems to be done quite a bit during initialisation, and quite a bit in various rather less common kinds of device, but not routinely in the main emulations.
Perhaps it would be better to invent a `logprintf' function to make it easier to redirect these kind of messages later if that turns out to be desirable ?
Ian.
Quoted 8 lines
Quoted 4 lines
Finally, it would perhaps be best if the block device emulators wrote to the qemu console to complain if they give write errors. Otherwise the errno value and other important information will be lost, which makes debugging hard.
If by 'qemu console' you mean stderr, then fine, but please don't spew log messages to the monitor console, because that'll make it very hard to interact with reliably from management tools.
Actually I think a better default would be for qemu to die right there and then. If the host is getting IO errors then something is badly wrong, and you're probably screwed anyway.
Paul
Quoted 5 lines · Paul Brook
Quoted 5 lines
Quoted 5 lines
Finally, it would perhaps be best if the block device emulators wrote to the qemu console to complain if they give write errors. Otherwise the errno value and other important information will be lost, which makes debugging hard.
Quoted 7 lines
Quoted 4 lines
If by 'qemu console' you mean stderr, then fine, but please don't spew log messages to the monitor console, because that'll make it very hard to interact with reliably from management tools.
Actually I think a better default would be for qemu to die right there and then. If the host is getting IO errors then something is badly wrong, and you're probably screwed anyway.
If you're passing through a real disk or volume, this denies the guest the possibility of recover y (for example, if it is running a RAID setup over multiple volumes, or if you are testing the guest's ability to recover from errors).
For non-raw formats, you can pass through errors on data, but it is impossible to recover on metadata errors, so dying on I/O error should be fine.
Signature · 1 line
Any sufficiently difficult bug is indistinguishable from a feature.
Avi Kivity writes ("Re: [Qemu-devel] [PATCH] bdrv_flush error handling"):
Quoted 3 lines
For non-raw formats, you can pass through errors on data, but it is impossible to recover on metadata errors, so dying on I/O error should be fine.
You mean metadata write errors I assume. I don't see why a metadata read error is any worse than any other read error.
The guest will often prefer to be told that the volume was broken and then to be denied the ability to continue accessing it. Who knows what the guest thinks of the device ? Perhaps it's an unimportant peripheral, or simulated network block device, used only for data interchange.
Write errors for non-raw formats can easily be caused by a disk full situation on the host. Killing the guest hard is unfriendly for that situation.
Ian.
Quoted 3 lines
Write errors for non-raw formats can easily be caused by a disk full situation on the host. Killing the guest hard is unfriendly for that situation.
Disk full is a fundamentally unfriendly situation to be in. There is no good answer. Reporting errors back to the host has its own set of problems. Many guest OS effectively just lock up when this occurs.
Paul
Paul Brook writes ("Re: [Qemu-devel] [PATCH] bdrv_flush error handling"):
Quoted 3 lines
Disk full is a fundamentally unfriendly situation to be in. There is no good answer. Reporting errors back to the host has its own set of problems. Many guest OS effectively just lock up when this occurs.
I think that's fine, surely ? A locked up guest isn't very nice but it's better than a guest shot dead.
Ian.
Quoted 7 lines · Ian Jackson
Paul Brook writes ("Re: [Qemu-devel] [PATCH]
bdrv_flusherror handling"):Quoted 3 lines
Disk full is a fundamentally unfriendly situation to be in. There is no good answer. Reporting errors back to the host has its own set of problems. Many guest OS effectively just lock up when this occurs.
I think that's fine, surely ? A locked up guest isn't very nice but it's better than a guest shot dead.
Well, a guest which receives an IDE write error might do things like mark parts of the device bad, to avoiding writing to those parts. If the guest is running software RAID, for example, it will radically change its behaviour in response to those errors.
Sometimes that's what you want, but sometimes it is really unwanted. If the host runs out of disk space, ideally you might want to suspend the guest until you can free up host disk space (or move to another host), then resume the guest, perhaps manually.
Is savevm-upon-disk-full a realistic prospect?
-- Jamie
Quoted 1 line
Is savevm-upon-disk-full a realistic prospect?
Not particularly useful. If you're run out of disk space, chances are that savevm will also fail.
Paul
Quoted 4 lines · Paul Brook
Quoted 1 line
Is savevm-upon-disk-full a realistic prospect?
Not particularly useful. If you're run out of disk space, chances are that savevm will also fail.
I'm imagining (a) that the savevm space is preallocated, or (b) is on a different disk.
-- Jamie
Quoted 14 lines · Jamie Lokier
Quoted 7 lines · Ian Jackson
Paul Brook writes ("Re: [Qemu-devel] [PATCH]
bdrv_flusherror handling"):Quoted 3 lines
Disk full is a fundamentally unfriendly situation to be in. There is no good answer. Reporting errors back to the host has its own set of problems. Many guest OS effectively just lock up when this occurs.
I think that's fine, surely ? A locked up guest isn't very nice but it's better than a guest shot dead.
Well, a guest which receives an IDE write error might do things like mark parts of the device bad, to avoiding writing to those parts. If the guest is running software RAID, for example, it will radically change its behaviour in response to those errors.
Quoted 6 lines
Sometimes that's what you want, but sometimes it is really unwanted. If the host runs out of disk space, ideally you might want to suspend the guest until you can free up host disk space (or move to another host), then resume the guest, perhaps manually.
Is savevm-upon-disk-full a realistic prospect?
In the 'out of disk space' scenario you wouldn't need to save the guest - merely stop its CPU. This gives the host admin the opportunity to hot-add storage to the host & then resume execution, or to kill the VM, or to free enough space to save the VM to disk / live migrate it to another host.
Shooting it dead on any I/O error doesn't give the host admin any choices at all
Dan.
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
Quoted 21 lines · Daniel P. Berrange
Quoted 19 lines · Jamie Lokier
Quoted 7 lines · Ian Jackson
Paul Brook writes ("Re: [Qemu-devel] [PATCH]
bdrv_flusherror handling"):Quoted 2 lines
Disk full is a fundamentally unfriendly situation to be in. There is no good answer. Reporting errors back to the host has its own set of problems. Many guest OS effectively just lock up when this occurs.
I think that's fine, surely ? A locked up guest isn't very nice but it's better than a guest shot dead.
Well, a guest which receives an IDE write error might do things like mark parts of the device bad, to avoiding writing to those parts. If the guest is running software RAID, for example, it will radically change its behaviour in response to those errors.
Sometimes that's what you want, but sometimes it is really unwanted. If the host runs out of disk space, ideally you might want to suspend the guest until you can free up host disk space (or move to another host), then resume the guest, perhaps manually.
Quoted 8 lines
Quoted 2 lines
Is savevm-upon-disk-full a realistic prospect?
In the 'out of disk space' scenario you wouldn't need to save the guest - merely stop its CPU. This gives the host admin the opportunity to hot-add storage to the host & then resume execution, or to kill the VM, or to free enough space to save the VM to disk / live migrate it to another host.
I agree. Stopping the CPUs and spitting out a big fat warning message would be the best thing to do. For the average user, this would give the opportunity to free up some space if possible.
Regards,
Anthony Liguori
Quoted 5 lines
Shooting it dead on any I/O error doesn't give the host admin any choices at all
Dan.
Quoted 4 lines · Anthony Liguori
Quoted 3 lines · Daniel P. Berrange
Quoted 2 lines · Jamie Lokier
Quoted 1 line · Ian Jackson
Paul Brook writes ("Re: [Qemu-devel] [PATCH]
bdrv_flusherror
handling"):
Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
Quoted 6 lines
Quoted 3 lines
Disk full is a fundamentally unfriendly situation to be in. There is no good answer. Reporting errors back to the host has its own set of problems. Many guest OS effectively just lock up when this occurs.
I think that's fine, surely ? A locked up guest isn't very nice but it's better than a guest shot dead.
Well, a guest which receives an IDE write error might do things like mark parts of the device bad, to avoiding writing to those parts. If the guest is running software RAID, for example, it will radically change its behaviour in response to those errors.
Sometimes that's what you want, but sometimes it is really unwanted. If the host runs out of disk space, ideally you might want to suspend the guest until you can free up host disk space (or move to another host), then resume the guest, perhaps manually.
Quoted 7 lines
Quoted 1 line
Is savevm-upon-disk-full a realistic prospect?
In the 'out of disk space' scenario you wouldn't need to save the guest - merely stop its CPU. This gives the host admin the opportunity to hot-add storage to the host & then resume execution, or to kill the VM, or to free enough space to save the VM to disk / live migrate it to another host.
Quoted 3 lines
I agree. Stopping the CPUs and spitting out a big fat warning message would be the best thing to do. For the average user, this would give the opportunity to free up some space if possible.
agreed.
Quoted 9 lines
Regards,
Anthony Liguori
Quoted 4 lines
Shooting it dead on any I/O error doesn't give the host admin any choices at all
Dan.
Sometimes the guest intentionally seeks the error. Example?
TrueCrypt 5.0 supports encryption of the full system disk. To get the real size of the disk, the truecrypt driver queries the number of blocks of the disk, but then tries to read after the last block, until it gets an error. Qemu hangs in this operation. So, for me, the blockdriver has to give the errors back to the guest (in this case, reading behind eof). In no cases, qemu should die because of that.
Tom
PS: I had to patch truecrypt because of this qemu feature.
Quoted 32 lines · ---- "Daniel P. Berrange
On Wed, Feb 20, 2008 at 03:53:46PM +0000, Ian Jackson wrote:
Content-Description: message body textQuoted 11 lines
bdrv_flushis declared to return void, but this is wrong because it means that the implementations have nowhere to report their errors. Indeed, the implementations generally ignore errors.This patch corrects this by making it return int (implicitly, either 0 or -errno, as for other similar functions). All of the implementations and callers are adjusted too.
While looking at this I was surprised to see this:
Quoted 8 lines
static void scsi_write_complete(void * opaque, int ret) ... if (ret) { fprintf(stderr, "scsi-disc: IO write error\n"); exit(1); }Surely that is overkill ?
Yes, any i/o errors I'd expect to be propagated back up to the guest OS as the most appropriate IDE / SCSI error code.
Quoted 7 lines
Also, in
block-raw-posix.c,raw_pwriteet al seem to return -1 on error (the return value from write) whereas the other block read/write methods return errno values. This is a mistake, surely ? -1 would be-EPERM. If any of the callers did anything with these return values you'd get incorrect error indications.
Quoted 8 lines
Quoted 4 lines
Finally, it would perhaps be best if the block device emulators wrote to the qemu console to complain if they give write errors. Otherwise the errno value and other important information will be lost, which makes debugging hard.
If by 'qemu console' you mean stderr, then fine, but please don't spew log messages to the monitor console, because that'll make it very hard to interact with reliably from management tools.
Would it make sense to have a log messages screen associated with the monitor (like Ctrl-Alt-7) to deal with those sorts of things?
Ben
Quoted 39 lines · Ben Taylor
Quoted 37 lines · ---- "Daniel P. Berrange
On Wed, Feb 20, 2008 at 03:53:46PM +0000, Ian Jackson wrote:
Content-Description: message body textQuoted 11 lines
bdrv_flushis declared to return void, but this is wrong because it means that the implementations have nowhere to report their errors. Indeed, the implementations generally ignore errors.This patch corrects this by making it return int (implicitly, either 0 or -errno, as for other similar functions). All of the implementations and callers are adjusted too.
While looking at this I was surprised to see this:
Quoted 8 lines
static void scsi_write_complete(void * opaque, int ret) ... if (ret) { fprintf(stderr, "scsi-disc: IO write error\n"); exit(1); }Surely that is overkill ?
Yes, any i/o errors I'd expect to be propagated back up to the guest OS as the most appropriate IDE / SCSI error code.
Quoted 11 lines
Also, in
block-raw-posix.c,raw_pwriteet al seem to return -1 on error (the return value from write) whereas the other block read/write methods return errno values. This is a mistake, surely ? -1 would be-EPERM. If any of the callers did anything with these return values you'd get incorrect error indications.Finally, it would perhaps be best if the block device emulators wrote to the qemu console to complain if they give write errors. Otherwise the errno value and other important information will be lost, which makes debugging hard.
Quoted 6 lines
Quoted 3 lines
If by 'qemu console' you mean stderr, then fine, but please don't spew log messages to the monitor console, because that'll make it very hard to interact with reliably from management tools.
Would it make sense to have a log messages screen associated with the monitor (like Ctrl-Alt-7) to deal with those sorts of things?
Why invent a new special QEMU log screen, when stderr works just fine. If an app wants to capture log messages they just capture stderr and persist it. We already capture stderr for exactly this reason in libvirt when managing QEMU instances.
Dan,
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
Quoted 47 lines · Daniel P. Berrange
Quoted 39 lines · Ben Taylor
Quoted 37 lines · ---- "Daniel P. Berrange
On Wed, Feb 20, 2008 at 03:53:46PM +0000, Ian Jackson wrote:
Content-Description: message body textQuoted 11 lines
bdrv_flushis declared to return void, but this is wrong because it means that the implementations have nowhere to report their errors. Indeed, the implementations generally ignore errors.This patch corrects this by making it return int (implicitly, either 0 or -errno, as for other similar functions). All of the implementations and callers are adjusted too.
While looking at this I was surprised to see this:
Quoted 8 lines
static void scsi_write_complete(void * opaque, int ret) ... if (ret) { fprintf(stderr, "scsi-disc: IO write error\n"); exit(1); }Surely that is overkill ?
Yes, any i/o errors I'd expect to be propagated back up to the guest OS as the most appropriate IDE / SCSI error code.
Quoted 11 lines
Also, in
block-raw-posix.c,raw_pwriteet al seem to return -1 on error (the return value from write) whereas the other block read/write methods return errno values. This is a mistake, surely ? -1 would be-EPERM. If any of the callers did anything with these return values you'd get incorrect error indications.Finally, it would perhaps be best if the block device emulators wrote to the qemu console to complain if they give write errors. Otherwise the errno value and other important information will be lost, which makes debugging hard.
Quoted 6 lines
Quoted 3 lines
If by 'qemu console' you mean stderr, then fine, but please don't spew log messages to the monitor console, because that'll make it very hard to interact with reliably from management tools.
Would it make sense to have a log messages screen associated with the monitor (like Ctrl-Alt-7) to deal with those sorts of things?
Quoted 12 lines
Why invent a new special QEMU log screen, when stderr works just fine. If an app wants to capture log messages they just capture stderr and persist it. We already capture stderr for exactly this reason in libvirt when managing QEMU instances.
Dan,
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
Please excuse my intrusion in this thread, but I'm a user of the new ncurses user interface. when ssh'd in, running qemu, I don't believe having messages pop out of stderr and over the current screen contents is the appropriate behavior, as it sounds to me like it would cause redraw defects in the normal text console (via ncurses)
Julia Longtin <[email protected]>
Quoted 26 lines · On Thu, Feb 21, 2008 at 11:28:23AM -0600, [email protected] wrote:
Quoted 17 lines · Daniel P. Berrange
Quoted 16 lines · Ben Taylor
Quoted 15 lines
Quoted 11 lines
Also, in
block-raw-posix.c,raw_pwriteet al seem to return -1 on error (the return value from write) whereas the other block read/write methods return errno values. This is a mistake, surely ? -1 would be-EPERM. If any of the callers did anything with these return values you'd get incorrect error indications.Finally, it would perhaps be best if the block device emulators wrote to the qemu console to complain if they give write errors. Otherwise the errno value and other important information will be lost, which makes debugging hard.
If by 'qemu console' you mean stderr, then fine, but please don't spew log messages to the monitor console, because that'll make it very hard to interact with reliably from management tools.
Quoted 7 lines
Quoted 2 lines
Would it make sense to have a log messages screen associated with the monitor (like Ctrl-Alt-7) to deal with those sorts of things?
Why invent a new special QEMU log screen, when stderr works just fine. If an app wants to capture log messages they just capture stderr and persist it. We already capture stderr for exactly this reason in libvirt when managing QEMU instances.
Quoted 5 lines
Please excuse my intrusion in this thread, but I'm a user of the new ncurses user interface. when ssh'd in, running qemu, I don't believe having messages pop out of stderr and over the current screen contents is the appropriate behavior, as it sounds to me like it would cause redraw defects in the normal text console (via ncurses)
So just redirect stderr to a logfile, or /dev/null, etc, etc
Dan.
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
Quoted 7 lines · On the 20th of February I wrote:
bdrv_flushis declared to return void, but this is wrong because it means that the implementations have nowhere to report their errors. Indeed, the implementations generally ignore errors.This patch corrects this by making it return int (implicitly, either 0 or -errno, as for other similar functions). All of the implementations and callers are adjusted too.
There was some discussion which I think concluded that this change was good but the patch doesn't seem to have been applied.
Ian.
tools/ioemu/block-qcow.c +4 -4
@@ -934,10 +934,10 @@ static int qcow_write_compressed(BlockDrreturn 0 ; } -static void qcow_flush (BlockDriverState *bs) -{ -BDRVQcowState *s = bs->opaque; -bdrv_flush (s->hd); +static int qcow_flush (BlockDriverState *bs) +{ +BDRVQcowState *s = bs->opaque; +return bdrv_flush (s->hd); }static int qcow_get_info (BlockDriverState *bs,BlockDriverInfo *bdi)
tools/ioemu/block-qcow2.c +4 -4
@@ -1235,10 +1235,10 @@ static int qcow_write_compressed(BlockDrreturn 0 ; } -static void qcow_flush (BlockDriverState *bs) -{ -BDRVQcowState *s = bs->opaque; -bdrv_flush (s->hd); +static int qcow_flush (BlockDriverState *bs) +{ +BDRVQcowState *s = bs->opaque; +return bdrv_flush (s->hd); }static int qcow_get_info (BlockDriverState *bs,BlockDriverInfo *bdi)
tools/ioemu/block-raw.c +6 -4
@@ -615,10 +615,12 @@ static int raw_create(const char *filenareturn 0 ; } -static void raw_flush (BlockDriverState *bs) -{ -BDRVRawState *s = bs->opaque; -fsync (s->fd); +static int raw_flush (BlockDriverState *bs) +{ +BDRVRawState *s = bs->opaque; +if (fsync (s->fd)) +return errno; +return 0 ; }BlockDriver bdrv_raw = {
tools/ioemu/block-vmdk.c +4 -4
@@ -734,10 +734,10 @@ static void vmdk_close(BlockDriverStatevmdk_parent_close (s->hd); } -static void vmdk_flush (BlockDriverState *bs) -{ -BDRVVmdkState *s = bs->opaque; -bdrv_flush (s->hd); +static int vmdk_flush (BlockDriverState *bs) +{ +BDRVVmdkState *s = bs->opaque; +return bdrv_flush (s->hd); }BlockDriver bdrv_vmdk = {
tools/ioemu/block.c +11 -8
@@ -889,12 +889,14 @@ const char *bdrv_get_device_name(BlockDrreturn bs->device_name; } -void bdrv_flush (BlockDriverState *bs) -{ -if (bs->drv->bdrv_flush) - bs->drv->bdrv_flush (bs); -if (bs->backing_hd) -bdrv_flush (bs->backing_hd); +int bdrv_flush (BlockDriverState *bs) +{ +int ret =0 ; +if (bs->drv->bdrv_flush) + ret = bs->drv->bdrv_flush (bs); +if (!ret && bs->backing_hd) + ret =bdrv_flush (bs->backing_hd); +return ret; }void bdrv_info (void )
@@ -1232,8 +1234,9 @@ static BlockDriverAIOCB *bdrv_aio_flush_static BlockDriverAIOCB *bdrv_aio_flush_em (BlockDriverState *bs,BlockDriverCompletionFunc *cb,void *opaque) { -bdrv_flush (bs); -cb (opaque,0 ); +int ret; + ret =bdrv_flush (bs); +cb (opaque, ret);return NULL ; }
tools/ioemu/block_int.h +1 -1
@@ -36,7 +36,7 @@ struct BlockDriver {void (*bdrv_close)(BlockDriverState *bs);int (*bdrv_create)(const char *filename,int64_t total_sectors,const char *backing_file,int flags); -void (*bdrv_flush)(BlockDriverState *bs); +int (*bdrv_flush)(BlockDriverState *bs);int (*bdrv_is_allocated)(BlockDriverState *bs,int64_t sector_num,int nb_sectors,int *pnum);int (*bdrv_set_key)(BlockDriverState *bs,const char *key);
tools/ioemu/hw/ide.c +1 -0
@@ -1786,6 +1786,7 @@ static void ide_ioport_write(void *opaquIDEState *s;int unit, n;int lba48 =0 ; +int ret;#ifdef DEBUG_IDE printf ("IDE: write addr=0x%x val=0x%02x\n" , addr, val);
tools/ioemu/hw/scsi-disk.c +7 -1
@@ -291,6 +291,7 @@ int32_t scsi_send_command(SCSIDevice *s,uint8_t command;uint8_t *outbuf;SCSIRequest *r; +int ret; command = buf[0 ]; r =scsi_find_request (s, tag);
@@ -496,7 +497,12 @@ int32_t scsi_send_command(SCSIDevice *s,break ;case 0x35 :DPRINTF ("Syncronise cache (sector %d, count %d)\n" , lba, len); -bdrv_flush (s->bdrv); + ret =bdrv_flush (s->bdrv); +if (ret) { +DPRINTF ("IO error on bdrv_flush\n" ); +scsi_command_complete (r,SENSE_HARDWARE_ERROR ); +return 0 ; + }break ;case 0x43 : {
tools/ioemu/vl.h +1 -1
@@ -664,7 +664,7 @@ void qemu_aio_wait_end(void);void qemu_aio_wait_end (void );/* Ensure contents are flushed to disk. */ -void bdrv_flush (BlockDriverState *bs); +int bdrv_flush (BlockDriverState *bs);#define BDRV_TYPE_HD 0#define BDRV_TYPE_CDROM 1
Quoted 11 lines · Ian Jackson
Quoted 7 lines · On the 20th of February I wrote:
bdrv_flushis declared to return void, but this is wrong because it means that the implementations have nowhere to report their errors. Indeed, the implementations generally ignore errors.This patch corrects this by making it return int (implicitly, either 0 or -errno, as for other similar functions). All of the implementations and callers are adjusted too.
There was some discussion which I think concluded that this change was good but the patch doesn't seem to have been applied.
It doesn't seem to apply against qemu, I could modify it but I don't know how block-raw-win32.c reports errors.
Regards
andrzej zaborowski writes ("Re: [Qemu-devel] Re: [PATCH] bdrv_flush error handling"):
Quoted 2 lines
It doesn't seem to apply against qemu, I could modify it but I don't know how
block-raw-win32.creports errors.
Thanks. I'll deal with it. I think it's just gone stale because the head has moved on.
Ian.