All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, Peter Lieven <pl@kamp.de>,
	ronniesahlberg@gmail.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCHv2 07/11] iscsi: let bdrv_create conditionally zero out the device
Date: Thu, 27 Jun 2013 15:11:31 +0200	[thread overview]
Message-ID: <1372338695-411-8-git-send-email-pl@kamp.de> (raw)
In-Reply-To: <1372338695-411-1-git-send-email-pl@kamp.de>

if the device supports unmapping and unmapped blocks read as
zero ensure that the whole device is unmapped and report
.has_zero_init = 1 in this case to speed up qemu-img convert.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block/iscsi.c |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 1 deletion(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 92e66a6..621ca40 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1436,7 +1436,8 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
 
 static int iscsi_has_zero_init(BlockDriverState *bs)
 {
-    return 0;
+    IscsiLun *iscsilun = bs->opaque;
+    return (iscsilun->lbpu && iscsilun->lbprz) ? 1 : 0;
 }
 
 static int iscsi_create(const char *filename, QEMUOptionParameter *options)
@@ -1446,6 +1447,7 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options)
     BlockDriverState bs;
     IscsiLun *iscsilun = NULL;
     QDict *bs_options;
+    struct scsi_task *task = NULL;
 
     memset(&bs, 0, sizeof(BlockDriverState));
 
@@ -1481,7 +1483,75 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options)
     }
 
     ret = 0;
+
+    if (iscsilun->lbpu && iscsilun->lbprz) {
+        uint64_t lba = 0;
+        while (lba < iscsilun->num_blocks) {
+            struct scsi_get_lba_status *lbas = NULL;
+            struct scsi_lba_status_descriptor *lbasd = NULL;
+            enum scsi_provisioning_type provisioning;
+            uint32_t nb_sectors;
+
+            task = iscsi_get_lba_status_sync(iscsilun->iscsi, iscsilun->lun,
+                                             lba, 8 + 16);
+            if (task == NULL || task->status != SCSI_STATUS_GOOD) {
+                error_report("iSCSI: Failed to get_lba_status on iSCSI lun. %s",
+                             iscsi_get_error(iscsilun->iscsi));
+                ret = -EINVAL;
+                goto out;
+            }
+
+            lbas = scsi_datain_unmarshall(task);
+            if (lbas == NULL) {
+                error_report("iSCSI: failed to unmarshall inquiry datain blob");
+                ret = -EINVAL;
+                goto out;
+            }
+            lbasd = &lbas->descriptors[0];
+            if (lbasd->lba != lba) {
+                ret = -EINVAL;
+                goto out;
+            }
+            nb_sectors = lbasd->num_blocks;
+            provisioning = lbasd->provisioning;
+            scsi_free_scsi_task(task);
+            task = NULL;
+
+            /* blocks from lba to lba + nb_sectors - 1 are not mapped
+             * and read as zero (lbprz==1) so we can skip them */
+            if (provisioning != SCSI_PROVISIONING_TYPE_MAPPED) {
+                lba += nb_sectors;
+                continue;
+            }
+
+            uint64_t lba2 = lba + nb_sectors;
+            while (lba < lba2) {
+                struct unmap_list list[1];
+                list[0].lba = lba;
+                list[0].num = iscsilun->max_unmap;
+                if (lba + list[0].num > iscsilun->num_blocks) {
+                    list[0].num = iscsilun->num_blocks - lba;
+                }
+                task = iscsi_unmap_sync(iscsilun->iscsi,
+                                        iscsilun->lun,
+                                        0, 0, &list[0], 1);
+                if (task == NULL || task->status != SCSI_STATUS_GOOD) {
+                    error_report("iSCSI: Failed to unmap data on iSCSI lun. %s",
+                                 iscsi_get_error(iscsilun->iscsi));
+                    ret = -EINVAL;
+                    goto out;
+                }
+                scsi_free_scsi_task(task);
+                task = NULL;
+                lba += list[0].num;
+            }
+        }
+    }
+
 out:
+    if (task) {
+        scsi_free_scsi_task(task);
+    }
     if (iscsilun->iscsi != NULL) {
         iscsi_destroy_context(iscsilun->iscsi);
     }
-- 
1.7.9.5

  parent reply	other threads:[~2013-06-27 13:13 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-27 13:11 [Qemu-devel] [PATCHv2 00/11] iscsi/qemu-img/block-migration enhancements Peter Lieven
2013-06-27 13:11 ` [Qemu-devel] [PATCHv2 01/11] iscsi: add logical block provisioning information to iscsilun Peter Lieven
2013-07-01 13:35   ` Stefan Hajnoczi
2013-07-01 16:08     ` Peter Lieven
2013-07-10  9:19   ` Kevin Wolf
2013-06-27 13:11 ` [Qemu-devel] [PATCHv2 02/11] iscsi: read unmap info from block limits vpd page Peter Lieven
2013-07-03  3:43   ` ronnie sahlberg
2013-07-03 21:23     ` Peter Lieven
2013-07-04 12:37       ` Paolo Bonzini
2013-07-04 21:07         ` Peter Lieven
2013-07-05  6:28           ` Paolo Bonzini
2013-07-05  7:11           ` ronnie sahlberg
2013-07-06 22:15             ` Peter Lieven
2013-07-06 23:23               ` ronnie sahlberg
2013-07-10  9:23   ` Kevin Wolf
2013-07-10  9:25   ` Kevin Wolf
2013-06-27 13:11 ` [Qemu-devel] [PATCHv2 03/11] iscsi: add bdrv_co_is_allocated Peter Lieven
2013-07-01 13:46   ` Stefan Hajnoczi
2013-07-01 16:00     ` Peter Lieven
2013-07-10  9:41   ` Kevin Wolf
2013-07-10 13:49     ` Peter Lieven
2013-07-10 14:43       ` Kevin Wolf
2013-07-10 14:49         ` Peter Lieven
2013-07-10 14:54           ` Kevin Wolf
2013-06-27 13:11 ` [Qemu-devel] [PATCHv2 04/11] iscsi: add bdrv_co_write_zeroes Peter Lieven
2013-07-10  9:54   ` Kevin Wolf
2013-06-27 13:11 ` [Qemu-devel] [PATCHv2 05/11] block: add bdrv_write_zeroes() Peter Lieven
2013-07-10  9:56   ` Kevin Wolf
2013-06-27 13:11 ` [Qemu-devel] [PATCHv2 06/11] block/raw: add bdrv_co_write_zeroes Peter Lieven
2013-07-10  9:57   ` Kevin Wolf
2013-06-27 13:11 ` Peter Lieven [this message]
2013-07-01 13:58   ` [Qemu-devel] [PATCHv2 07/11] iscsi: let bdrv_create conditionally zero out the device Stefan Hajnoczi
2013-07-01 20:20   ` Paolo Bonzini
2013-07-01 21:36     ` Peter Lieven
2013-07-02  9:22       ` Paolo Bonzini
2013-07-02 10:36         ` Peter Lieven
2013-07-02 10:49           ` Paolo Bonzini
2013-07-02 10:56             ` Peter Lieven
2013-07-02 11:04               ` Paolo Bonzini
2013-07-02 11:18                 ` Peter Lieven
2013-07-10 10:14   ` Kevin Wolf
2013-07-10 13:52     ` Peter Lieven
2013-06-27 13:11 ` [Qemu-devel] [PATCHv2 08/11] block-migration: efficiently encode zero blocks Peter Lieven
2013-07-01 14:13   ` Stefan Hajnoczi
2013-07-01 15:55     ` Peter Lieven
2013-07-02  7:40       ` Stefan Hajnoczi
2013-07-02 10:51         ` Paolo Bonzini
2013-07-01 16:09     ` Peter Lieven
2013-07-02  7:36       ` Stefan Hajnoczi
2013-06-27 13:11 ` [Qemu-devel] [PATCHv2 09/11] iscsi: factor out sector conversions Peter Lieven
2013-07-10 11:29   ` Kevin Wolf
2013-07-10 14:07     ` Peter Lieven
2013-06-27 13:11 ` [Qemu-devel] [PATCHv2 10/11] iscsi: ignore aio_discard if unsupported Peter Lieven
2013-07-10 11:33   ` Kevin Wolf
2013-07-10 14:04     ` Peter Lieven
2013-07-10 14:28       ` Kevin Wolf
2013-07-10 14:49         ` Peter Lieven
2013-07-10 14:58           ` Kevin Wolf
2013-07-10 20:31             ` Peter Lieven
2013-06-27 13:11 ` [Qemu-devel] [PATCHv2 11/11] iscsi: assert that sectors are aligned to LUN blocksize Peter Lieven
2013-07-01 14:35   ` Stefan Hajnoczi
2013-07-01 15:59     ` Peter Lieven
2013-07-02  7:44       ` Stefan Hajnoczi
2013-07-02  8:28         ` Peter Lieven
2013-07-02 10:44           ` Paolo Bonzini
2013-07-02 10:49             ` Peter Lieven
2013-07-02 10:53               ` Paolo Bonzini
2013-07-10 11:38   ` Kevin Wolf
2013-07-10 14:02     ` Peter Lieven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1372338695-411-8-git-send-email-pl@kamp.de \
    --to=pl@kamp.de \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.