iSCSI fix crash when using virtio and libiscsi V3
PATCH 1/1 iSCSI fix crash when using virtio and libiscsi V3
List,
Please find a new version of the patch to fix the iSCSI crash when ioctl with iovector is sent.
Updated to fix the commit message as per lerseks suggestion.
Also added an explicit cast to suppress a compiler warning when we dont have iovector support available.
PATCH 1/1 Fix iSCSI crash on SG_IO with an iovector
Don't assume that SG_IO is always invoked with a simple buffer, check the iovec_count and if it is >= 1 then we need to pass an array of iovectors to libiscsi instead of just a plain buffer.
--- block/iscsi.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 49 insertions(+), 7 deletions(-)
block/iscsi.c +49 -7
@@ -651,6 +651,9 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status, {IscsiAIOCB *acb = opaque; +g_free (acb->buf); + acb->buf =NULL ; +if (acb->canceled !=0 ) {return ; }
@@ -727,14 +730,36 @@ static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,memcpy (&acb->task->cdb[0 ], acb->ioh->cmdp, acb->ioh->cmd_len); acb->task->expxferlen = acb->ioh->dxfer_len; + data.size =0 ;if (acb->task->xfer_dir ==SCSI_XFER_WRITE ) { - data.data = acb->ioh->dxferp; - data.size = acb->ioh->dxfer_len; +if (acb->ioh->iovec_count ==0 ) { + data.data = acb->ioh->dxferp; + data.size = acb->ioh->dxfer_len; + }else { +#if defined(LIBISCSI_FEATURE_IOVECTOR ) +scsi_task_set_iov_out (acb->task, + (struct scsi_iovec *) acb->ioh->dxferp, + acb->ioh->iovec_count); +#else +int i; +char *buf; +struct scsi_iovec *iov = (struct scsi_iovec *)acb->ioh->dxferp; + + acb->buf =g_malloc (acb->ioh->dxfer_len); + buf = (char *)acb->buf; +for (i =0 ; i < acb->ioh->iovec_count; i++) { +memcpy (buf, iov[i].iov_base, iov[i].iov_len); + buf += iov[i].iov_len; + } + data.data = acb->buf; + data.size = acb->ioh->dxfer_len; +#endif + } } +if (iscsi_scsi_command_async (iscsi, iscsilun->lun, acb->task, iscsi_aio_ioctl_cb, - (acb->task->xfer_dir ==SCSI_XFER_WRITE ) ? - &data :NULL , + (data.size >0 ) ? &data :NULL , acb) !=0 ) {scsi_free_scsi_task (acb->task);qemu_aio_release (acb);
@@ -743,9 +768,26 @@ static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,/* tell libiscsi to read straight into the buffer we got from ioctl */ if (acb->task->xfer_dir ==SCSI_XFER_READ ) { -scsi_task_add_data_in_buffer (acb->task, - acb->ioh->dxfer_len, - acb->ioh->dxferp); +if (acb->ioh->iovec_count ==0 ) { +scsi_task_add_data_in_buffer (acb->task, + acb->ioh->dxfer_len, + acb->ioh->dxferp); + }else { +#if defined(LIBISCSI_FEATURE_IOVECTOR ) +scsi_task_set_iov_in (acb->task, + (struct scsi_iovec *) acb->ioh->dxferp, + acb->ioh->iovec_count); +#else +int i; +for (i =0 ; i < acb->ioh->iovec_count; i++) { +struct scsi_iovec *iov = (struct scsi_iovec *)acb->ioh->dxferp; + +scsi_task_add_data_in_buffer (acb->task, + iov[i].iov_len, + iov[i].iov_base); + } +#endif + } }iscsi_set_events (iscsilun);
Signature · 1 line
1.7.3.1
Re: [Qemu-devel] [PATCH] Fix iSCSI crash on SG_IO with an iovector
Quoted 85 lines · Ronnie Sahlberg
Don't assume that
SG_IOis always invoked with a simple buffer, check theiovec_countand if it is >= 1 then we need to pass an array of iovectors to libiscsi instead of just a plain buffer.Signed-off-by Ronnie Sahlberg <[email protected]>--- block/iscsi.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 49 insertions(+), 7 deletions(-)block/iscsi.c +42
-7@@ -651,6 +651,9 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status, {IscsiAIOCB *acb = opaque; +g_free (acb->buf); + acb->buf =NULL ; +if (acb->canceled !=0 ) {return ; }@@ -727,14 +730,36 @@ static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,memcpy (&acb->task->cdb[0 ], acb->ioh->cmdp, acb->ioh->cmd_len); acb->task->expxferlen = acb->ioh->dxfer_len; + data.size =0 ;if (acb->task->xfer_dir ==SCSI_XFER_WRITE ) { - data.data = acb->ioh->dxferp; - data.size = acb->ioh->dxfer_len; +if (acb->ioh->iovec_count ==0 ) { + data.data = acb->ioh->dxferp; + data.size = acb->ioh->dxfer_len; + }else { +#if defined(LIBISCSI_FEATURE_IOVECTOR ) +scsi_task_set_iov_out (acb->task, + (struct scsi_iovec *) acb->ioh->dxferp, + acb->ioh->iovec_count); +#else +int i; +char *buf; +struct scsi_iovec *iov = (struct scsi_iovec *)acb->ioh->dxferp; + + acb->buf =g_malloc (acb->ioh->dxfer_len); + buf = (char *)acb->buf; +for (i =0 ; i < acb->ioh->iovec_count; i++) { +memcpy (buf, iov[i].iov_base, iov[i].iov_len); + buf += iov[i].iov_len; + } + data.data = acb->buf; + data.size = acb->ioh->dxfer_len; +#endif + } } +if (iscsi_scsi_command_async (iscsi, iscsilun->lun, acb->task, iscsi_aio_ioctl_cb, - (acb->task->xfer_dir ==SCSI_XFER_WRITE ) ? - &data :NULL , + (data.size >0 ) ? &data :NULL , acb) !=0 ) {scsi_free_scsi_task (acb->task);qemu_aio_release (acb);@@ -743,9 +768,26 @@ static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,/* tell libiscsi to read straight into the buffer we got from ioctl */ if (acb->task->xfer_dir ==SCSI_XFER_READ ) { -scsi_task_add_data_in_buffer (acb->task, - acb->ioh->dxfer_len, - acb->ioh->dxferp); +if (acb->ioh->iovec_count ==0 ) { +scsi_task_add_data_in_buffer (acb->task, + acb->ioh->dxfer_len, + acb->ioh->dxferp); + }else { +#if defined(LIBISCSI_FEATURE_IOVECTOR ) +scsi_task_set_iov_in (acb->task, + (struct scsi_iovec *) acb->ioh->dxferp, + acb->ioh->iovec_count); +#else +int i; +for (i =0 ; i < acb->ioh->iovec_count; i++) { +struct scsi_iovec *iov = (struct scsi_iovec *)acb->ioh->dxferp;
block/iscsi.c static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, · line 793
Quoted 10 lines
block/iscsi.c +7
-0+ +scsi_task_add_data_in_buffer (acb->task, + iov[i].iov_len, + iov[i].iov_base); + } +#endif + } }iscsi_set_events (iscsilun);
Re: [Qemu-devel] [PATCH] Fix iSCSI crash on SG_IO with an iovector
In reply to Ronnie SahlbergIl 23/06/2013 17:07, Ronnie Sahlberg ha scritto:
Quoted 8 lines
Don't assume that
SG_IOis always invoked with a simple buffer, check theiovec_countand if it is >= 1 then we need to pass an array of iovectors to libiscsi instead of just a plain buffer.Signed-off-by Ronnie Sahlberg <[email protected]>--- block/iscsi.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 49 insertions(+), 7 deletions(-)
Will apply to scsi-next in the next few days.
Paolo
Quoted 86 lines
block/iscsi.c +49
-7@@ -651,6 +651,9 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status, {IscsiAIOCB *acb = opaque; +g_free (acb->buf); + acb->buf =NULL ; +if (acb->canceled !=0 ) {return ; }@@ -727,14 +730,36 @@ static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,memcpy (&acb->task->cdb[0 ], acb->ioh->cmdp, acb->ioh->cmd_len); acb->task->expxferlen = acb->ioh->dxfer_len; + data.size =0 ;if (acb->task->xfer_dir ==SCSI_XFER_WRITE ) { - data.data = acb->ioh->dxferp; - data.size = acb->ioh->dxfer_len; +if (acb->ioh->iovec_count ==0 ) { + data.data = acb->ioh->dxferp; + data.size = acb->ioh->dxfer_len; + }else { +#if defined(LIBISCSI_FEATURE_IOVECTOR ) +scsi_task_set_iov_out (acb->task, + (struct scsi_iovec *) acb->ioh->dxferp, + acb->ioh->iovec_count); +#else +int i; +char *buf; +struct scsi_iovec *iov = (struct scsi_iovec *)acb->ioh->dxferp; + + acb->buf =g_malloc (acb->ioh->dxfer_len); + buf = (char *)acb->buf; +for (i =0 ; i < acb->ioh->iovec_count; i++) { +memcpy (buf, iov[i].iov_base, iov[i].iov_len); + buf += iov[i].iov_len; + } + data.data = acb->buf; + data.size = acb->ioh->dxfer_len; +#endif + } } +if (iscsi_scsi_command_async (iscsi, iscsilun->lun, acb->task, iscsi_aio_ioctl_cb, - (acb->task->xfer_dir ==SCSI_XFER_WRITE ) ? - &data :NULL , + (data.size >0 ) ? &data :NULL , acb) !=0 ) {scsi_free_scsi_task (acb->task);qemu_aio_release (acb);@@ -743,9 +768,26 @@ static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,/* tell libiscsi to read straight into the buffer we got from ioctl */ if (acb->task->xfer_dir ==SCSI_XFER_READ ) { -scsi_task_add_data_in_buffer (acb->task, - acb->ioh->dxfer_len, - acb->ioh->dxferp); +if (acb->ioh->iovec_count ==0 ) { +scsi_task_add_data_in_buffer (acb->task, + acb->ioh->dxfer_len, + acb->ioh->dxferp); + }else { +#if defined(LIBISCSI_FEATURE_IOVECTOR ) +scsi_task_set_iov_in (acb->task, + (struct scsi_iovec *) acb->ioh->dxferp, + acb->ioh->iovec_count); +#else +int i; +for (i =0 ; i < acb->ioh->iovec_count; i++) { +struct scsi_iovec *iov = (struct scsi_iovec *)acb->ioh->dxferp; + +scsi_task_add_data_in_buffer (acb->task, + iov[i].iov_len, + iov[i].iov_base); + } +#endif + } }iscsi_set_events (iscsilun);
Re: [Qemu-devel] [PATCH] Fix iSCSI crash on SG_IO with an iovector
Quoted 5 lines · Paolo Bonzini
Il 23/06/2013 17:07, Ronnie Sahlberg ha scritto:
Quoted 4 lines
Don't assume that
SG_IOis always invoked with a simple buffer, check theiovec_countand if it is >= 1 then we need to pass an array of iovectors to libiscsi instead of just a plain buffer.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Ronnie Sahlberg <[email protected]>--- block/iscsi.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 49 insertions(+), 7 deletions(-)Will apply to scsi-next in the next few days.
Paolo, there are small whitespace issues that you might like to fix when merging:
Quoted 5 lines
block/iscsi.c static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, · line 742
Quoted 5 lines
block/iscsi.c +5
-0+ }else { +#if defined(LIBISCSI_FEATURE_IOVECTOR ) +scsi_task_set_iov_out (acb->task, + (struct scsi_iovec *) acb->ioh->dxferp, + acb->ioh->iovec_count);
Should be 4-space indentation.
Quoted 1 line
Quoted 1 line
+ #else
Space before #else?
Re: [Qemu-devel] [PATCH] Fix iSCSI crash on SG_IO with an iovector
Il 25/06/2013 11:24, Stefan Hajnoczi ha scritto:
Quoted 11 lines · Paolo Bonzini
Quoted 10 lines
Il 23/06/2013 17:07, Ronnie Sahlberg ha scritto:
Quoted 8 lines
Don't assume that
SG_IOis always invoked with a simple buffer, check theiovec_countand if it is >= 1 then we need to pass an array of iovectors to libiscsi instead of just a plain buffer.Signed-off-by Ronnie Sahlberg <[email protected]>--- block/iscsi.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 49 insertions(+), 7 deletions(-)
Quoted 6 lines
Quoted 3 lines
Will apply to scsi-next in the next few days.
Paolo, there are small whitespace issues that you might like to fix when merging:
Yup, will do.
Paolo
Quoted 12 lines
Quoted 5 lines
block/iscsi.c static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, · line 742
Quoted 5 lines
block/iscsi.c +5
-0+ }else { +#if defined(LIBISCSI_FEATURE_IOVECTOR ) +scsi_task_set_iov_out (acb->task, + (struct scsi_iovec *) acb->ioh->dxferp, + acb->ioh->iovec_count);Should be 4-space indentation.
Quoted 1 line
Quoted 1 line
+ #else
Space before #else?