9ae3a8
From 615429e3068cb4a3e57ee60d52f318aa6ca06f6d Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <615429e3068cb4a3e57ee60d52f318aa6ca06f6d.1389014116.git.minovotn@redhat.com>
9ae3a8
In-Reply-To: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
9ae3a8
References: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
9ae3a8
From: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Date: Mon, 9 Dec 2013 14:09:22 +0100
9ae3a8
Subject: [PATCH 34/50] block/iscsi: check WRITE SAME support differently
9ae3a8
 depending on MAY_UNMAP
9ae3a8
9ae3a8
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Message-id: <1386598178-11845-37-git-send-email-pbonzini@redhat.com>
9ae3a8
Patchwork-id: 56073
9ae3a8
O-Subject: [RHEL 7.0 qemu-kvm PATCH 36/52] block/iscsi: check WRITE SAME support differently depending on MAY_UNMAP
9ae3a8
Bugzilla: 1007815
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
The current check is right for MAY_UNMAP=1.  For MAY_UNMAP=0, just
9ae3a8
try and fall back to regular writes as soon as a WRITE SAME command
9ae3a8
fails.
9ae3a8
9ae3a8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Reviewed-by: Peter Lieven <pl@kamp.de>
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
(cherry picked from commit fa6252b0565526ec2347e248172f91771e0d9f47)
9ae3a8
---
9ae3a8
 block/iscsi.c | 19 +++++++++++++++++--
9ae3a8
 1 file changed, 17 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
---
9ae3a8
 block/iscsi.c | 19 +++++++++++++++++--
9ae3a8
 1 file changed, 17 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/iscsi.c b/block/iscsi.c
9ae3a8
index 7ae61f9..8b82fe7 100644
9ae3a8
--- a/block/iscsi.c
9ae3a8
+++ b/block/iscsi.c
9ae3a8
@@ -55,6 +55,7 @@ typedef struct IscsiLun {
9ae3a8
     QEMUTimer *nop_timer;
9ae3a8
     uint8_t lbpme;
9ae3a8
     uint8_t lbprz;
9ae3a8
+    uint8_t has_write_same;
9ae3a8
     struct scsi_inquiry_logical_block_provisioning lbp;
9ae3a8
     struct scsi_inquiry_block_limits bl;
9ae3a8
     unsigned char *zeroblock;
9ae3a8
@@ -978,8 +979,13 @@ coroutine_fn iscsi_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
9ae3a8
         return -EINVAL;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    if (!iscsilun->lbp.lbpws) {
9ae3a8
-        /* WRITE SAME is not supported by the target */
9ae3a8
+    if (!(flags & BDRV_REQ_MAY_UNMAP) && !iscsilun->has_write_same) {
9ae3a8
+        /* WRITE SAME without UNMAP is not supported by the target */
9ae3a8
+        return -ENOTSUP;
9ae3a8
+    }
9ae3a8
+
9ae3a8
+    if ((flags & BDRV_REQ_MAY_UNMAP) && !iscsilun->lbp.lbpws) {
9ae3a8
+        /* WRITE SAME with UNMAP is not supported by the target */
9ae3a8
         return -ENOTSUP;
9ae3a8
     }
9ae3a8
 
9ae3a8
@@ -1014,6 +1020,14 @@ retry:
9ae3a8
     }
9ae3a8
 
9ae3a8
     if (iTask.status != SCSI_STATUS_GOOD) {
9ae3a8
+        if (iTask.status == SCSI_STATUS_CHECK_CONDITION &&
9ae3a8
+            iTask.task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST &&
9ae3a8
+            iTask.task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
9ae3a8
+            /* WRITE SAME is not supported by the target */
9ae3a8
+            iscsilun->has_write_same = false;
9ae3a8
+            return -ENOTSUP;
9ae3a8
+        }
9ae3a8
+
9ae3a8
         return -EIO;
9ae3a8
     }
9ae3a8
 
9ae3a8
@@ -1377,6 +1391,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
     }
9ae3a8
 
9ae3a8
     iscsilun->type = inq->periperal_device_type;
9ae3a8
+    iscsilun->has_write_same = true;
9ae3a8
 
9ae3a8
     if ((ret = iscsi_readcapacity_sync(iscsilun)) != 0) {
9ae3a8
         goto out;
9ae3a8
-- 
9ae3a8
1.7.11.7
9ae3a8