yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
958e1b
From ce9c2ba7bd509d0d92c6f5a12ea27b9899126d6d Mon Sep 17 00:00:00 2001
240766
From: Fam Zheng <famz@redhat.com>
240766
Date: Fri, 4 Apr 2014 05:55:58 +0200
240766
Subject: [PATCH 03/12] block/iscsi: query for supported VPD pages
240766
240766
RH-Author: Fam Zheng <famz@redhat.com>
240766
Message-id: <1396590962-25815-4-git-send-email-famz@redhat.com>
240766
Patchwork-id: 58340
240766
O-Subject: [RHEL-7 0day qemu-kvm PATCH 3/7] block/iscsi: query for supported VPD pages
958e1b
Bugzilla: 1083413
240766
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
240766
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
240766
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
240766
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
240766
240766
From: Peter Lieven <pl@kamp.de>
240766
240766
this patch ensures that we only query for block provisioning and
240766
block limits vpd pages if they are advertised. It also cleans
240766
up the inquiry code and eliminates some redundant code.
240766
240766
Signed-off-by: Peter Lieven <pl@kamp.de>
240766
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
240766
(cherry picked from commit 24d3bd67aca958c8ea103646d9d326de00056e4d)
240766
Signed-off-by: Fam Zheng <famz@redhat.com>
240766
---
240766
 block/iscsi.c | 107 +++++++++++++++++++++++++++++-----------------------------
240766
 1 file changed, 54 insertions(+), 53 deletions(-)
240766
240766
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
240766
---
240766
 block/iscsi.c |  107 +++++++++++++++++++++++++++++----------------------------
240766
 1 files changed, 54 insertions(+), 53 deletions(-)
240766
240766
diff --git a/block/iscsi.c b/block/iscsi.c
240766
index 537d2cb..d3c8802 100644
240766
--- a/block/iscsi.c
240766
+++ b/block/iscsi.c
240766
@@ -1240,7 +1240,7 @@ static QemuOptsList runtime_opts = {
240766
 };
240766
 
240766
 static struct scsi_task *iscsi_do_inquiry(struct iscsi_context *iscsi, int lun,
240766
-                                          int evpd, int pc, Error **errp)
240766
+                                          int evpd, int pc, void **inq, Error **errp)
240766
 {
240766
     int full_size;
240766
     struct scsi_task *task = NULL;
240766
@@ -1259,14 +1259,19 @@ static struct scsi_task *iscsi_do_inquiry(struct iscsi_context *iscsi, int lun,
240766
         }
240766
     }
240766
 
240766
+    *inq = scsi_datain_unmarshall(task);
240766
+    if (*inq == NULL) {
240766
+        error_setg(errp, "iSCSI: failed to unmarshall inquiry datain blob");
240766
+        goto fail;
240766
+    }
240766
+
240766
     return task;
240766
 
240766
 fail:
240766
     error_setg(errp, "iSCSI: Inquiry command failed : %s",
240766
                iscsi_get_error(iscsi));
240766
-    if (task) {
240766
+    if (task != NULL) {
240766
         scsi_free_scsi_task(task);
240766
-        return NULL;
240766
     }
240766
     return NULL;
240766
 }
240766
@@ -1283,11 +1288,12 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
240766
     struct iscsi_url *iscsi_url = NULL;
240766
     struct scsi_task *task = NULL;
240766
     struct scsi_inquiry_standard *inq = NULL;
240766
+    struct scsi_inquiry_supported_pages *inq_vpd;
240766
     char *initiator_name = NULL;
240766
     QemuOpts *opts;
240766
     Error *local_err = NULL;
240766
     const char *filename;
240766
-    int ret;
240766
+    int i, ret;
240766
 
240766
     if ((BDRV_SECTOR_SIZE % 512) != 0) {
240766
         error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
240766
@@ -1373,24 +1379,17 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
240766
 
240766
     iscsilun->iscsi = iscsi;
240766
     iscsilun->lun   = iscsi_url->lun;
240766
+    iscsilun->has_write_same = true;
240766
 
240766
-    task = iscsi_inquiry_sync(iscsi, iscsilun->lun, 0, 0, 36);
240766
-
240766
-    if (task == NULL || task->status != SCSI_STATUS_GOOD) {
240766
-        error_setg(errp, "iSCSI: failed to send inquiry command.");
240766
-        ret = -EINVAL;
240766
-        goto out;
240766
-    }
240766
-
240766
-    inq = scsi_datain_unmarshall(task);
240766
-    if (inq == NULL) {
240766
-        error_setg(errp, "iSCSI: Failed to unmarshall inquiry data.");
240766
+    task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 0, 0,
240766
+                            (void **) &inq, errp);
240766
+    if (task == NULL) {
240766
         ret = -EINVAL;
240766
         goto out;
240766
     }
240766
-
240766
     iscsilun->type = inq->periperal_device_type;
240766
-    iscsilun->has_write_same = true;
240766
+    scsi_free_scsi_task(task);
240766
+    task = NULL;
240766
 
240766
     iscsi_readcapacity_sync(iscsilun, &local_err);
240766
     if (local_err != NULL) {
240766
@@ -1408,46 +1407,48 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
240766
         bs->sg = 1;
240766
     }
240766
 
240766
-    if (iscsilun->lbpme) {
240766
-        struct scsi_inquiry_logical_block_provisioning *inq_lbp;
240766
-        task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1,
240766
-                                SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING,
240766
-                                errp);
240766
-        if (task == NULL) {
240766
-            ret = -EINVAL;
240766
-            goto out;
240766
-        }
240766
-        inq_lbp = scsi_datain_unmarshall(task);
240766
-        if (inq_lbp == NULL) {
240766
-            error_setg(errp, "iSCSI: failed to unmarshall inquiry datain blob");
240766
-            ret = -EINVAL;
240766
-            goto out;
240766
-        }
240766
-        memcpy(&iscsilun->lbp, inq_lbp,
240766
-               sizeof(struct scsi_inquiry_logical_block_provisioning));
240766
-        scsi_free_scsi_task(task);
240766
-        task = NULL;
240766
+    task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1,
240766
+                            SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES,
240766
+                            (void **) &inq_vpd, errp);
240766
+    if (task == NULL) {
240766
+        ret = -EINVAL;
240766
+        goto out;
240766
     }
240766
-
240766
-    if (iscsilun->lbp.lbpu || iscsilun->lbp.lbpws) {
240766
+    for (i = 0; i < inq_vpd->num_pages; i++) {
240766
+        struct scsi_task *inq_task;
240766
+        struct scsi_inquiry_logical_block_provisioning *inq_lbp;
240766
         struct scsi_inquiry_block_limits *inq_bl;
240766
-        task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1,
240766
-                                SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, errp);
240766
-        if (task == NULL) {
240766
-            ret = -EINVAL;
240766
-            goto out;
240766
-        }
240766
-        inq_bl = scsi_datain_unmarshall(task);
240766
-        if (inq_bl == NULL) {
240766
-            error_setg(errp, "iSCSI: failed to unmarshall inquiry datain blob");
240766
-            ret = -EINVAL;
240766
-            goto out;
240766
+        switch (inq_vpd->pages[i]) {
240766
+        case SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING:
240766
+            inq_task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1,
240766
+                                        SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING,
240766
+                                        (void **) &inq_lbp, errp);
240766
+            if (inq_task == NULL) {
240766
+                ret = -EINVAL;
240766
+                goto out;
240766
+            }
240766
+            memcpy(&iscsilun->lbp, inq_lbp,
240766
+                   sizeof(struct scsi_inquiry_logical_block_provisioning));
240766
+            scsi_free_scsi_task(inq_task);
240766
+            break;
240766
+        case SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS:
240766
+            inq_task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1,
240766
+                                    SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS,
240766
+                                    (void **) &inq_bl, errp);
240766
+            if (inq_task == NULL) {
240766
+                ret = -EINVAL;
240766
+                goto out;
240766
+            }
240766
+            memcpy(&iscsilun->bl, inq_bl,
240766
+                   sizeof(struct scsi_inquiry_block_limits));
240766
+            scsi_free_scsi_task(inq_task);
240766
+            break;
240766
+        default:
240766
+            break;
240766
         }
240766
-        memcpy(&iscsilun->bl, inq_bl,
240766
-               sizeof(struct scsi_inquiry_block_limits));
240766
-        scsi_free_scsi_task(task);
240766
-        task = NULL;
240766
     }
240766
+    scsi_free_scsi_task(task);
240766
+    task = NULL;
240766
 
240766
 #if defined(LIBISCSI_FEATURE_NOP_COUNTER)
240766
     /* Set up a timer for sending out iSCSI NOPs */
240766
-- 
240766
1.7.1
240766