From: Ronnie Sahlberg <ronniesahlberg@gmail.com>
To: qemu-devel@nongnu.org
Cc: stefanha@gmail.com, 1191606@bugs.launchpad.net,
lersek@redhat.com, Ronnie Sahlberg <ronniesahlberg@gmail.com>,
pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH] Fix iSCSI crash on SG_IO with an iovector
Date: Fri, 21 Jun 2013 18:37:18 -0700 [thread overview]
Message-ID: <1371865038-20821-2-git-send-email-ronniesahlberg@gmail.com> (raw)
In-Reply-To: <1371865038-20821-1-git-send-email-ronniesahlberg@gmail.com>
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.
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
---
block/iscsi.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/block/iscsi.c b/block/iscsi.c
index 0bbf0b1..cbe2e8f 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -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 = 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);
--
1.7.3.1
next prev parent reply other threads:[~2013-06-22 1:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-22 1:37 [Qemu-devel] [PATCH] iSCSI fix crash when using virtio and libiscsi V2 Ronnie Sahlberg
2013-06-22 1:37 ` Ronnie Sahlberg [this message]
2013-06-23 10:01 ` [Qemu-devel] [PATCH] Fix iSCSI crash on SG_IO with an iovector Laszlo Ersek
2013-06-25 9:21 ` Stefan Hajnoczi
-- strict thread matches above, loose matches on Subject: below --
2013-06-23 15:07 [Qemu-devel] [PATCH] iSCSI fix crash when using virtio and libiscsi V3 Ronnie Sahlberg
2013-06-23 15:07 ` [Qemu-devel] [PATCH] Fix iSCSI crash on SG_IO with an iovector Ronnie Sahlberg
2013-06-23 15:23 ` Laszlo Ersek
2013-06-24 14:40 ` Paolo Bonzini
2013-06-25 9:24 ` Stefan Hajnoczi
2013-06-25 10:42 ` Paolo Bonzini
2013-06-21 2:32 [Qemu-devel] [PATCH] iSCSI fix crash when using virtio and libiscsi Ronnie Sahlberg
2013-06-21 2:32 ` [Qemu-devel] [PATCH] Fix iSCSI crash on SG_IO with an iovector Ronnie Sahlberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1371865038-20821-2-git-send-email-ronniesahlberg@gmail.com \
--to=ronniesahlberg@gmail.com \
--cc=1191606@bugs.launchpad.net \
--cc=lersek@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).