cryptospore / rpms / qemu-kvm

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