Blame SOURCES/kvm-iscsi-add-logical-block-provisioning-information-to-.patch.patch

0a122b
From 7f3514b0392635f132a8e1158d91536e5aed7783 Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <7f3514b0392635f132a8e1158d91536e5aed7783.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:08:51 +0100
0a122b
Subject: [PATCH 03/50] iscsi: add logical block provisioning information to
0a122b
 iscsilun
0a122b
0a122b
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Message-id: <1386598178-11845-6-git-send-email-pbonzini@redhat.com>
0a122b
Patchwork-id: 56042
0a122b
O-Subject: [RHEL 7.0 qemu-kvm PATCH 05/52] iscsi: add logical block provisioning information to iscsilun
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: Paolo Bonzini <pbonzini@redhat.com>
0a122b
(cherry picked from commit f18a7cbb0992a02225d26afd336aaf47de75e11c)
0a122b
---
0a122b
 block/iscsi.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0a122b
 1 file changed, 77 insertions(+)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 block/iscsi.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0a122b
 1 file changed, 77 insertions(+)
0a122b
0a122b
diff --git a/block/iscsi.c b/block/iscsi.c
0a122b
index 8086957..6804b6d 100644
0a122b
--- a/block/iscsi.c
0a122b
+++ b/block/iscsi.c
0a122b
@@ -52,6 +52,10 @@ typedef struct IscsiLun {
0a122b
     uint64_t num_blocks;
0a122b
     int events;
0a122b
     QEMUTimer *nop_timer;
0a122b
+    uint8_t lbpme;
0a122b
+    uint8_t lbprz;
0a122b
+    struct scsi_inquiry_logical_block_provisioning lbp;
0a122b
+    struct scsi_inquiry_block_limits bl;
0a122b
 } IscsiLun;
0a122b
 
0a122b
 typedef struct IscsiAIOCB {
0a122b
@@ -1005,6 +1009,8 @@ static int iscsi_readcapacity_sync(IscsiLun *iscsilun)
0a122b
                 } else {
0a122b
                     iscsilun->block_size = rc16->block_length;
0a122b
                     iscsilun->num_blocks = rc16->returned_lba + 1;
0a122b
+                    iscsilun->lbpme = rc16->lbpme;
0a122b
+                    iscsilun->lbprz = rc16->lbprz;
0a122b
                 }
0a122b
             }
0a122b
             break;
0a122b
@@ -1057,6 +1063,37 @@ static QemuOptsList runtime_opts = {
0a122b
     },
0a122b
 };
0a122b
 
0a122b
+static struct scsi_task *iscsi_do_inquiry(struct iscsi_context *iscsi,
0a122b
+                                          int lun, int evpd, int pc) {
0a122b
+        int full_size;
0a122b
+        struct scsi_task *task = NULL;
0a122b
+        task = iscsi_inquiry_sync(iscsi, lun, evpd, pc, 64);
0a122b
+        if (task == NULL || task->status != SCSI_STATUS_GOOD) {
0a122b
+            goto fail;
0a122b
+        }
0a122b
+        full_size = scsi_datain_getfullsize(task);
0a122b
+        if (full_size > task->datain.size) {
0a122b
+            scsi_free_scsi_task(task);
0a122b
+
0a122b
+            /* we need more data for the full list */
0a122b
+            task = iscsi_inquiry_sync(iscsi, lun, evpd, pc, full_size);
0a122b
+            if (task == NULL || task->status != SCSI_STATUS_GOOD) {
0a122b
+                goto fail;
0a122b
+            }
0a122b
+        }
0a122b
+
0a122b
+        return task;
0a122b
+
0a122b
+fail:
0a122b
+        error_report("iSCSI: Inquiry command failed : %s",
0a122b
+                     iscsi_get_error(iscsi));
0a122b
+        if (task) {
0a122b
+            scsi_free_scsi_task(task);
0a122b
+            return NULL;
0a122b
+        }
0a122b
+        return NULL;
0a122b
+}
0a122b
+
0a122b
 /*
0a122b
  * We support iscsi url's on the form
0a122b
  * iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
0a122b
@@ -1187,6 +1224,46 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
         bs->sg = 1;
0a122b
     }
0a122b
 
0a122b
+    if (iscsilun->lbpme) {
0a122b
+        struct scsi_inquiry_logical_block_provisioning *inq_lbp;
0a122b
+        task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1,
0a122b
+                                SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING);
0a122b
+        if (task == NULL) {
0a122b
+            ret = -EINVAL;
0a122b
+            goto out;
0a122b
+        }
0a122b
+        inq_lbp = scsi_datain_unmarshall(task);
0a122b
+        if (inq_lbp == NULL) {
0a122b
+            error_report("iSCSI: failed to unmarshall inquiry datain blob");
0a122b
+            ret = -EINVAL;
0a122b
+            goto out;
0a122b
+        }
0a122b
+        memcpy(&iscsilun->lbp, inq_lbp,
0a122b
+               sizeof(struct scsi_inquiry_logical_block_provisioning));
0a122b
+        scsi_free_scsi_task(task);
0a122b
+        task = NULL;
0a122b
+    }
0a122b
+
0a122b
+    if (iscsilun->lbp.lbpu || iscsilun->lbp.lbpws) {
0a122b
+        struct scsi_inquiry_block_limits *inq_bl;
0a122b
+        task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1,
0a122b
+                                SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS);
0a122b
+        if (task == NULL) {
0a122b
+            ret = -EINVAL;
0a122b
+            goto out;
0a122b
+        }
0a122b
+        inq_bl = scsi_datain_unmarshall(task);
0a122b
+        if (inq_bl == NULL) {
0a122b
+            error_report("iSCSI: failed to unmarshall inquiry datain blob");
0a122b
+            ret = -EINVAL;
0a122b
+            goto out;
0a122b
+        }
0a122b
+        memcpy(&iscsilun->bl, inq_bl,
0a122b
+               sizeof(struct scsi_inquiry_block_limits));
0a122b
+        scsi_free_scsi_task(task);
0a122b
+        task = NULL;
0a122b
+    }
0a122b
+
0a122b
 #if defined(LIBISCSI_FEATURE_NOP_COUNTER)
0a122b
     /* Set up a timer for sending out iSCSI NOPs */
0a122b
     iscsilun->nop_timer = qemu_new_timer_ms(rt_clock, iscsi_nop_timed_event, iscsilun);
0a122b
-- 
0a122b
1.7.11.7
0a122b