scsi-disk: Complete rerror/werror support
v2 cover scsi-disk: Complete rerror/werror support
SCSI disks currently only support werror for write requests. This series adds rerror for failed read requests and respects werror also for flushes.
v2:
- Addressed Stefan's comments on patch 1/4
Kevin Wolf (4):
scsi-disk: Implement rerror option
block: Allow bdrv_flush to return errors
scsi-disk: Complete failed requests in scsi_disk_emulate_command
scsi-disk: Implement werror for flushes
block.c | 21 +++++++-- block.h | 2 +- block/blkdebug.c | 4 +- block/blkverify.c | 4 +- block/cow.c | 4 +- block/qcow.c | 4 +- block/qcow2.c | 4 +- block/raw-posix.c | 4 +- block/raw-win32.c | 9 +++- block/raw.c | 4 +- block/vdi.c | 4 +- block/vmdk.c | 4 +- block_int.h | 2 +- blockdev.c | 6 +- hw/scsi-disk.c | 138 +++++++++++++++++++++++++++++++++++------------------ 15 files changed, 140 insertions(+), 74 deletions(-)
Signature · 1 line
1.7.2.3
PATCH v2 1/4 scsi-disk: Implement rerror option
This implements the rerror option for SCSI disks.
It also includes minor changes to the write path where the same code is used that was criticized in the review for the changes to the read path required for rerror support.
--- blockdev.c | 6 ++-- hw/scsi-disk.c | 100 +++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 69 insertions(+), 37 deletions(-)
blockdev.c +3 -3
@@ -314,7 +314,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) on_write_error =BLOCK_ERR_STOP_ENOSPC ;if ((buf =qemu_opt_get (opts,"werror" )) !=NULL ) {if (type !=IF_IDE && type !=IF_SCSI && type !=IF_VIRTIO && type !=IF_NONE ) { -fprintf (stderr,"werror is no supported by this format\n" ); +fprintf (stderr,"werror is not supported by this format\n" );return NULL ; }
@@ -326,8 +326,8 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) on_read_error =BLOCK_ERR_REPORT ;if ((buf =qemu_opt_get (opts,"rerror" )) !=NULL ) { -if (type !=IF_IDE && type !=IF_VIRTIO && type !=IF_NONE ) { -fprintf (stderr,"rerror is no supported by this format\n" ); +if (type !=IF_IDE && type !=IF_VIRTIO && type !=IF_SCSI && type !=IF_NONE ) { +fprintf (stderr,"rerror is not supported by this format\n" );return NULL ; }
hw/scsi-disk.c +66 -34
177 lines not on this page · raw message
Signature · 1 line
1.7.2.3
[Qemu-devel] Re: [PATCH v2 1/4] scsi-disk: Implement rerror option
Quoted 11 lines · Kevin Wolf
This implements the rerror option for SCSI disks.
It also includes minor changes to the write path where the same code is used that was criticized in the review for the changes to the read path required for rerror support.
Signed-off-by Kevin Wolf <[email protected]>---
blockdev.c | 6 ++--
hw/scsi-disk.c | 100 +++++++++++++++++++++++++++++++++++++-------------------2 files changed, 69 insertions(+), 37 deletions(-)
Looks good.
PATCH v2 2/4 block: Allow bdrv_flush to return errors
In reply to Kevin WolfThis changes bdrv_flush to return 0 on success and -errno in case of failure. It's a requirement for implementing proper error handle in users of bdrv_flush.
--- block.c | 21 +++++++++++++++++---- block.h | 2 +- block/blkdebug.c | 4 ++-- block/blkverify.c | 4 ++-- block/cow.c | 4 ++-- block/qcow.c | 4 ++-- block/qcow2.c | 4 ++-- block/raw-posix.c | 4 ++-- block/raw-win32.c | 9 ++++++++- block/raw.c | 4 ++-- block/vdi.c | 4 ++-- block/vmdk.c | 4 ++-- block_int.h | 2 +- 13 files changed, 45 insertions(+), 25 deletions(-)
block.c +17 -4
@@ -1453,14 +1453,27 @@ const char *bdrv_get_device_name(BlockDriverState *bs)return bs->device_name; } -void bdrv_flush (BlockDriverState *bs) +int bdrv_flush (BlockDriverState *bs) {if (bs->open_flags &BDRV_O_NO_FLUSH ) { -return ; +return 0 ; + } + +if (bs->drv && bs->drv->bdrv_flush) { +return bs->drv->bdrv_flush (bs); } -if (bs->drv && bs->drv->bdrv_flush) - bs->drv->bdrv_flush (bs); +/* +* Some block drivers always operate in either writethrough or unsafe mode +* and don't support bdrv_flush therefore. Usually qemu doesn't know how +* the server works (because the behaviour is hardcoded or depends on +* server-side configuration), so we can't ensure that everything is safe +* on disk. Returning an error doesn't work because that would break guests +* even if the server operates in writethrough mode. +* +* Let's hope the user knows what he's doing. +*/ +return 0 ; }void bdrv_flush_all (void )
block.h +1 -1
@@ -142,7 +142,7 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque);/* Ensure contents are flushed to disk. */ -void bdrv_flush (BlockDriverState *bs); +int bdrv_flush (BlockDriverState *bs);void bdrv_flush_all (void );void bdrv_close_all (void );
block/blkdebug.c +2 -2
@@ -397,9 +397,9 @@ static void blkdebug_close(BlockDriverState *bs) } } -static void blkdebug_flush (BlockDriverState *bs) +static int blkdebug_flush (BlockDriverState *bs) { -bdrv_flush (bs->file); +return bdrv_flush (bs->file); } static BlockDriverAIOCB *blkdebug_aio_flush(BlockDriverState *bs,
block/blkverify.c +2 -2
@@ -116,12 +116,12 @@ static void blkverify_close(BlockDriverState *bs) s->test_file =NULL ; } -static void blkverify_flush (BlockDriverState *bs) +static int blkverify_flush (BlockDriverState *bs) {BDRVBlkverifyState *s = bs->opaque;/* Only flush test file, the raw file is not important */ -bdrv_flush (s->test_file); +return bdrv_flush (s->test_file); }static int64_t blkverify_getlength (BlockDriverState *bs)
block/cow.c +2 -2
@@ -282,9 +282,9 @@ exit:return ret; } -static void cow_flush (BlockDriverState *bs) +static int cow_flush (BlockDriverState *bs) { -bdrv_flush (bs->file); +return bdrv_flush (bs->file); }static QEMUOptionParameter cow_create_options[] = {
block/qcow.c +2 -2
@@ -910,9 +910,9 @@ 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) { -bdrv_flush (bs->file); +return bdrv_flush (bs->file); } static BlockDriverAIOCB *qcow_aio_flush(BlockDriverState *bs,
block/qcow2.c +2 -2
@@ -1148,9 +1148,9 @@ 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) { -bdrv_flush (bs->file); +return bdrv_flush (bs->file); } static BlockDriverAIOCB *qcow_aio_flush(BlockDriverState *bs,
block/raw-posix.c +2 -2
@@ -734,10 +734,10 @@ static int raw_create(const char *filename, QEMUOptionParameter *options)return result; } -static void raw_flush (BlockDriverState *bs) +static int raw_flush (BlockDriverState *bs) {BDRVRawState *s = bs->opaque; -qemu_fdatasync (s->fd); +return qemu_fdatasync (s->fd); }
block/raw-win32.c +8 -1
@@ -150,7 +150,14 @@ static int raw_write(BlockDriverState *bs, int64_t sector_num,static void raw_flush (BlockDriverState *bs) {BDRVRawState *s = bs->opaque; -FlushFileBuffers (s->hfile); +int ret; + + ret =FlushFileBuffers (s->hfile); +if (ret !=0 ) { +return -EIO ; + } + +return 0 ; }static void raw_close (BlockDriverState *bs)
block/raw.c +2 -2
@@ -39,9 +39,9 @@ static void raw_close(BlockDriverState *bs) { } -static void raw_flush (BlockDriverState *bs) +static int raw_flush (BlockDriverState *bs) { -bdrv_flush (bs->file); +return bdrv_flush (bs->file); } static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs,
block/vdi.c +2 -2
@@ -900,10 +900,10 @@ static void vdi_close(BlockDriverState *bs) { } -static void vdi_flush (BlockDriverState *bs) +static int vdi_flush (BlockDriverState *bs) {logout ("\n" ); -bdrv_flush (bs->file); +return bdrv_flush (bs->file); }
block/vmdk.c +2 -2
@@ -823,9 +823,9 @@ static void vmdk_close(BlockDriverState *bs)qemu_free (s->l2_cache); } -static void vmdk_flush (BlockDriverState *bs) +static int vmdk_flush (BlockDriverState *bs) { -bdrv_flush (bs->file); +return bdrv_flush (bs->file); }
block_int.h +1 -1
@@ -59,7 +59,7 @@ struct BlockDriver { const uint8_t *buf, int nb_sectors);void (*bdrv_close)(BlockDriverState *bs);int (*bdrv_create)(const char *filename,QEMUOptionParameter *options); -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);
Signature · 1 line
1.7.2.3
PATCH v2 3/4 scsi-disk: Complete failed requests in scsi_disk_emulate_command
In reply to Kevin WolfThis pulls the request completion for error cases from the caller to scsi_disk_emulate_command. This should not change semantics, but allows to reuse scsi_handle_write_error() for flushes in the next patch.
--- hw/scsi-disk.c | 21 ++++++++++----------- 1 files changed, 10 insertions(+), 11 deletions(-)
hw/scsi-disk.c +10 -11
@@ -784,8 +784,9 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)return toclen; } -static int scsi_disk_emulate_command (SCSIRequest *req,uint8_t *outbuf) +static int scsi_disk_emulate_command (SCSIDiskReq *r,uint8_t *outbuf) { +SCSIRequest *req = &r->req;SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, req->dev);uint64_t nb_sectors;int buflen =0 ;
@@ -943,12 +944,12 @@ static int scsi_disk_emulate_command(SCSIRequest *req, uint8_t *outbuf)return buflen; not_ready: -scsi_req_set_status (req,CHECK_CONDITION ,NOT_READY ); -return 0 ; +scsi_command_complete (r,CHECK_CONDITION ,NOT_READY ); +return -1 ; illegal_request: -scsi_req_set_status (req,CHECK_CONDITION ,ILLEGAL_REQUEST ); -return 0 ; +scsi_command_complete (r,CHECK_CONDITION ,ILLEGAL_REQUEST ); +return -1 ; }/* Execute a scsi command. Returns the length of the data expected by the
@@ -1056,14 +1057,12 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,case REPORT_LUNS :case VERIFY :case REZERO_UNIT : - rc =scsi_disk_emulate_command (&r->req, outbuf); -if (rc >0 ) { - r->iov.iov_len = rc; - }else { -scsi_req_complete (&r->req); -scsi_remove_request (r); + rc =scsi_disk_emulate_command (r, outbuf); +if (rc <0 ) {return 0 ; } + + r->iov.iov_len = rc;break ;case READ_6 :case READ_10 :
Signature · 1 line
1.7.2.3
PATCH v2 4/4 scsi-disk: Implement werror for flushes
In reply to Kevin Wolf--- hw/scsi-disk.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)
hw/scsi-disk.c +16 -1
@@ -45,6 +45,7 @@ do { fprintf(stderr, "scsi-disk: " fmt , ## __VA_ARGS__); } while (0)#define SCSI_REQ_STATUS_RETRY_TYPE_MASK 0x06#define SCSI_REQ_STATUS_RETRY_READ 0x00#define SCSI_REQ_STATUS_RETRY_WRITE 0x02 +#define SCSI_REQ_STATUS_RETRY_FLUSH 0x04typedef struct SCSIDiskState SCSIDiskState ;
@@ -74,6 +75,7 @@ struct SCSIDiskState };static int scsi_handle_rw_error (SCSIDiskReq *r,int error,int type); +static int scsi_disk_emulate_command (SCSIDiskReq *r,uint8_t *outbuf);static SCSIDiskReq *scsi_new_request (SCSIDiskState *s,uint32_t tag,uint32_t lun)
@@ -316,6 +318,8 @@ static void scsi_dma_restart_bh(void *opaque) r =DO_UPCAST (SCSIDiskReq, req, req);if (r->status &SCSI_REQ_STATUS_RETRY ) {int status = r->status; +int ret; + r->status &= ~(SCSI_REQ_STATUS_RETRY |SCSI_REQ_STATUS_RETRY_TYPE_MASK );
@@ -326,6 +330,11 @@ static void scsi_dma_restart_bh(void *opaque)case SCSI_REQ_STATUS_RETRY_WRITE :scsi_write_request (r);break ; +case SCSI_REQ_STATUS_RETRY_FLUSH : + ret =scsi_disk_emulate_command (r, r->iov.iov_base); +if (ret ==0 ) { +scsi_command_complete (r,GOOD ,NO_SENSE ); + } } } }
@@ -790,6 +799,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, req->dev);uint64_t nb_sectors;int buflen =0 ; +int ret;switch (req->cmd.buf[0 ]) {case TEST_UNIT_READY :
@@ -880,7 +890,12 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) buflen =8 ;break ;case SYNCHRONIZE_CACHE : -bdrv_flush (s->bs); + ret =bdrv_flush (s->bs); +if (ret <0 ) { +if (scsi_handle_rw_error (r, -ret,SCSI_REQ_STATUS_RETRY_FLUSH )) { +return -1 ; + } + }break ;case GET_CONFIGURATION :memset (outbuf,0 ,8 );
Signature · 1 line
1.7.2.3
Quoted 5 lines · Kevin Wolf
SCSI disks currently only support werror for write requests. This series adds rerror for failed read requests and respects werror also for flushes.
v2:
- Addressed Stefan's comments on patch 1/4
Looks good.
Stefan