From 4790b03d308f6c7dea7dc6941ddab9867c9530b8 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 22 Jan 2013 17:34:29 +0100 Subject: iscsi: do not leak acb->buf when commands are aborted acb->buf is freed in the WRITE(16) callback, but this may not get called at all when commands are aborted. Add another free in the ABORT TASK callback, which requires setting acb->buf to NULL everywhere. Signed-off-by: Paolo Bonzini --- block/iscsi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block/iscsi.c b/block/iscsi.c index fd54a15..b647201 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -77,6 +77,9 @@ iscsi_bh_cb(void *p) qemu_bh_delete(acb->bh); + g_free(acb->buf); + acb->buf = NULL; + if (acb->canceled == 0) { acb->common.cb(acb->common.opaque, acb->status); } @@ -198,6 +201,7 @@ iscsi_aio_write16_cb(struct iscsi_context *iscsi, int status, trace_iscsi_aio_write16_cb(iscsi, status, acb, acb->canceled); g_free(acb->buf); + acb->buf = NULL; if (acb->canceled != 0) { return; @@ -241,6 +245,7 @@ iscsi_aio_writev(BlockDriverState *bs, int64_t sector_num, acb->canceled = 0; acb->bh = NULL; acb->status = -EINPROGRESS; + acb->buf = NULL; /* XXX we should pass the iovec to write16 to avoid the extra copy */ /* this will allow us to get rid of 'buf' completely */ @@ -249,7 +254,6 @@ iscsi_aio_writev(BlockDriverState *bs, int64_t sector_num, /* if the iovec only contains one buffer we can pass it directly */ if (acb->qiov->niov == 1) { - acb->buf = NULL; data.data = acb->qiov->iov[0].iov_base; } else { acb->buf = g_malloc(data.size); @@ -440,6 +444,7 @@ iscsi_aio_flush(BlockDriverState *bs, acb->canceled = 0; acb->bh = NULL; acb->status = -EINPROGRESS; + acb->buf = NULL; acb->task = iscsi_synchronizecache10_task(iscsi, iscsilun->lun, 0, 0, 0, 0, @@ -493,6 +498,7 @@ iscsi_aio_discard(BlockDriverState *bs, acb->canceled = 0; acb->bh = NULL; acb->status = -EINPROGRESS; + acb->buf = NULL; list[0].lba = sector_qemu2lun(sector_num, iscsilun); list[0].num = nb_sectors * BDRV_SECTOR_SIZE / iscsilun->block_size; -- cgit v1.1 From 7371d56fb2759f52106c76692440d0c29731ef9c Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Mon, 3 Dec 2012 20:35:15 +0100 Subject: iscsi: add support for iovectors This patch adds support for directly passing the iovec array from QEMUIOVector if libiscsi supports it (1.8.0 or newer). Signed-off-by: Peter Lieven [Preserve the improvements from commit 4cc841b, iscsi: partly avoid iovec linearization in iscsi_aio_writev, 2012-11-19 - Paolo] Signed-off-by: Paolo Bonzini --- block/iscsi.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index b647201..deb3b68 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -234,7 +234,10 @@ iscsi_aio_writev(BlockDriverState *bs, int64_t sector_num, size_t size; uint32_t num_sectors; uint64_t lba; +#if !defined(LIBISCSI_FEATURE_IOVECTOR) struct iscsi_data data; +#endif + int ret; acb = qemu_aio_get(&iscsi_aiocb_info, bs, cb, opaque); trace_iscsi_aio_writev(iscsi, sector_num, nb_sectors, opaque, acb); @@ -247,9 +250,10 @@ iscsi_aio_writev(BlockDriverState *bs, int64_t sector_num, acb->status = -EINPROGRESS; acb->buf = NULL; - /* XXX we should pass the iovec to write16 to avoid the extra copy */ /* this will allow us to get rid of 'buf' completely */ size = nb_sectors * BDRV_SECTOR_SIZE; + +#if !defined(LIBISCSI_FEATURE_IOVECTOR) data.size = MIN(size, acb->qiov->size); /* if the iovec only contains one buffer we can pass it directly */ @@ -260,6 +264,7 @@ iscsi_aio_writev(BlockDriverState *bs, int64_t sector_num, qemu_iovec_to_buf(acb->qiov, 0, acb->buf, data.size); data.data = acb->buf; } +#endif acb->task = malloc(sizeof(struct scsi_task)); if (acb->task == NULL) { @@ -280,16 +285,28 @@ iscsi_aio_writev(BlockDriverState *bs, int64_t sector_num, *(uint32_t *)&acb->task->cdb[10] = htonl(num_sectors); acb->task->expxferlen = size; - if (iscsi_scsi_command_async(iscsi, iscsilun->lun, acb->task, - iscsi_aio_write16_cb, - &data, - acb) != 0) { +#if defined(LIBISCSI_FEATURE_IOVECTOR) + ret = iscsi_scsi_command_async(iscsi, iscsilun->lun, acb->task, + iscsi_aio_write16_cb, + NULL, + acb); +#else + ret = iscsi_scsi_command_async(iscsi, iscsilun->lun, acb->task, + iscsi_aio_write16_cb, + &data, + acb); +#endif + if (ret != 0) { scsi_free_scsi_task(acb->task); g_free(acb->buf); qemu_aio_release(acb); return NULL; } +#if defined(LIBISCSI_FEATURE_IOVECTOR) + scsi_task_set_iov_out(acb->task, (struct scsi_iovec*) acb->qiov->iov, acb->qiov->niov); +#endif + iscsi_set_events(iscsilun); return &acb->common; @@ -327,7 +344,10 @@ iscsi_aio_readv(BlockDriverState *bs, int64_t sector_num, struct iscsi_context *iscsi = iscsilun->iscsi; IscsiAIOCB *acb; size_t qemu_read_size; +#if !defined(LIBISCSI_FEATURE_IOVECTOR) int i; +#endif + int ret; uint64_t lba; uint32_t num_sectors; @@ -389,20 +409,25 @@ iscsi_aio_readv(BlockDriverState *bs, int64_t sector_num, break; } - if (iscsi_scsi_command_async(iscsi, iscsilun->lun, acb->task, - iscsi_aio_read16_cb, - NULL, - acb) != 0) { + ret = iscsi_scsi_command_async(iscsi, iscsilun->lun, acb->task, + iscsi_aio_read16_cb, + NULL, + acb); + if (ret != 0) { scsi_free_scsi_task(acb->task); qemu_aio_release(acb); return NULL; } +#if defined(LIBISCSI_FEATURE_IOVECTOR) + scsi_task_set_iov_in(acb->task, (struct scsi_iovec*) acb->qiov->iov, acb->qiov->niov); +#else for (i = 0; i < acb->qiov->niov; i++) { scsi_task_add_data_in_buffer(acb->task, acb->qiov->iov[i].iov_len, acb->qiov->iov[i].iov_base); } +#endif iscsi_set_events(iscsilun); -- cgit v1.1