From 0923f651d0a8ec837dc2c85dc6fbb9cfabd86172 Mon Sep 17 00:00:00 2001 Message-Id: <0923f651d0a8ec837dc2c85dc6fbb9cfabd86172.1389014116.git.minovotn@redhat.com> In-Reply-To: References: From: Paolo Bonzini Date: Mon, 9 Dec 2013 14:09:06 +0100 Subject: [PATCH 18/50] iscsi: add bdrv_co_write_zeroes RH-Author: Paolo Bonzini Message-id: <1386598178-11845-21-git-send-email-pbonzini@redhat.com> Patchwork-id: 56057 O-Subject: [RHEL 7.0 qemu-kvm PATCH 20/52] iscsi: add bdrv_co_write_zeroes Bugzilla: 1007815 RH-Acked-by: Jeffrey Cody RH-Acked-by: Fam Zheng RH-Acked-by: Stefan Hajnoczi From: Peter Lieven Signed-off-by: Peter Lieven Signed-off-by: Stefan Hajnoczi (cherry picked from commit d4cd961507e6f013fd0f9b1dc609f15ed2aaa40d) --- block/iscsi.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) Signed-off-by: Michal Novotny --- block/iscsi.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/block/iscsi.c b/block/iscsi.c index 567a63a..3e3ae64 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -56,6 +56,7 @@ typedef struct IscsiLun { uint8_t lbprz; struct scsi_inquiry_logical_block_provisioning lbp; struct scsi_inquiry_block_limits bl; + unsigned char *zeroblock; } IscsiLun; typedef struct IscsiTask { @@ -961,6 +962,65 @@ retry: return 0; } +#if defined(SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED) + +static int +coroutine_fn iscsi_co_write_zeroes(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, BdrvRequestFlags flags) +{ + IscsiLun *iscsilun = bs->opaque; + struct IscsiTask iTask; + uint64_t lba; + uint32_t nb_blocks; + + if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) { + return -EINVAL; + } + + if (!iscsilun->lbp.lbpws) { + /* WRITE SAME is not supported by the target */ + return -ENOTSUP; + } + + lba = sector_qemu2lun(sector_num, iscsilun); + nb_blocks = sector_qemu2lun(nb_sectors, iscsilun); + + if (iscsilun->zeroblock == NULL) { + iscsilun->zeroblock = g_malloc0(iscsilun->block_size); + } + + iscsi_co_init_iscsitask(iscsilun, &iTask); +retry: + if (iscsi_writesame16_task(iscsilun->iscsi, iscsilun->lun, lba, + iscsilun->zeroblock, iscsilun->block_size, + nb_blocks, 0, !!(flags & BDRV_REQ_MAY_UNMAP), + 0, 0, iscsi_co_generic_cb, &iTask) == NULL) { + return -EIO; + } + + while (!iTask.complete) { + iscsi_set_events(iscsilun); + qemu_coroutine_yield(); + } + + if (iTask.task != NULL) { + scsi_free_scsi_task(iTask.task); + iTask.task = NULL; + } + + if (iTask.do_retry) { + goto retry; + } + + if (iTask.status != SCSI_STATUS_GOOD) { + return -EIO; + } + + return 0; +} + +#endif /* SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED */ + static int parse_chap(struct iscsi_context *iscsi, const char *target) { QemuOptsList *list; @@ -1423,6 +1483,7 @@ static void iscsi_close(BlockDriverState *bs) } qemu_aio_set_fd_handler(iscsi_get_fd(iscsi), NULL, NULL, NULL, NULL); iscsi_destroy_context(iscsi); + g_free(iscsilun->zeroblock); memset(iscsilun, 0, sizeof(IscsiLun)); } @@ -1538,6 +1599,9 @@ static BlockDriver bdrv_iscsi = { .bdrv_co_get_block_status = iscsi_co_get_block_status, .bdrv_co_discard = iscsi_co_discard, +#if defined(SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED) + .bdrv_co_write_zeroes = iscsi_co_write_zeroes, +#endif .bdrv_aio_readv = iscsi_aio_readv, .bdrv_aio_writev = iscsi_aio_writev, -- 1.7.11.7