qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	pbonzini@redhat.com, Peter Lieven <pl@kamp.de>,
	ronniesahlberg@gmail.com, Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH 1/2] iscsi: add support for bdrv_co_is_allocated()
Date: Thu, 20 Jun 2013 20:20:08 +0200	[thread overview]
Message-ID: <1371752409-16313-2-git-send-email-pl@kamp.de> (raw)
In-Reply-To: <1371752409-16313-1-git-send-email-pl@kamp.de>

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

diff --git a/block/iscsi.c b/block/iscsi.c
index 0bbf0b1..e6b966d 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -49,6 +49,7 @@ typedef struct IscsiLun {
     uint64_t num_blocks;
     int events;
     QEMUTimer *nop_timer;
+    uint8_t lbpme;
 } IscsiLun;
 
 typedef struct IscsiAIOCB {
@@ -800,6 +801,60 @@ iscsi_getlength(BlockDriverState *bs)
     return len;
 }
 
+static int coroutine_fn iscsi_co_is_allocated(BlockDriverState *bs,
+                                              int64_t sector_num,
+                                              int nb_sectors, int *pnum)
+{
+    IscsiLun *iscsilun = bs->opaque;
+    struct scsi_task *task = NULL;
+    struct scsi_get_lba_status *lbas = NULL;
+    struct scsi_lba_status_descriptor *lbasd = NULL;
+    int ret;
+
+    *pnum = nb_sectors;
+
+    if (iscsilun->lbpme == 0) {
+        return 1;
+    }
+
+    /* in-flight requests could invalidate the lba status result */
+    while (iscsi_process_flush(iscsilun)) {
+        qemu_aio_wait();
+    }
+
+    task = iscsi_get_lba_status_sync(iscsilun->iscsi, iscsilun->lun,
+                                     sector_qemu2lun(sector_num, iscsilun),
+                                     8+16);
+
+    if (task == NULL || task->status != SCSI_STATUS_GOOD) {
+        scsi_free_scsi_task(task);
+        return 1;
+    }
+
+    lbas = scsi_datain_unmarshall(task);
+    if (lbas == NULL) {
+        scsi_free_scsi_task(task);
+        return 1;
+    }
+
+    lbasd = &lbas->descriptors[0];
+
+    if (sector_qemu2lun(sector_num, iscsilun) != lbasd->lba) {
+        return 1;
+    }
+
+    *pnum = lbasd->num_blocks * (iscsilun->block_size / BDRV_SECTOR_SIZE);
+    if (*pnum > nb_sectors) {
+        *pnum = nb_sectors;
+    }
+
+    ret = (lbasd->provisioning == SCSI_PROVISIONING_TYPE_MAPPED) ? 1 : 0;
+
+    scsi_free_scsi_task(task);
+
+    return ret;
+}
+
 static int parse_chap(struct iscsi_context *iscsi, const char *target)
 {
     QemuOptsList *list;
@@ -948,6 +1003,7 @@ static int iscsi_readcapacity_sync(IscsiLun *iscsilun)
                 } else {
                     iscsilun->block_size = rc16->block_length;
                     iscsilun->num_blocks = rc16->returned_lba + 1;
+                    iscsilun->lbpme = rc16->lbpme;
                 }
             }
             break;
@@ -1274,6 +1330,7 @@ static BlockDriver bdrv_iscsi = {
 
     .bdrv_aio_discard = iscsi_aio_discard,
     .bdrv_has_zero_init = iscsi_has_zero_init,
+    .bdrv_co_is_allocated = iscsi_co_is_allocated,
 
 #ifdef __linux__
     .bdrv_ioctl       = iscsi_ioctl,
-- 
1.7.9.5

  reply	other threads:[~2013-06-20 18:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-20 18:20 [Qemu-devel] [PATCH 0/2] iscsi: support for is_allocated and inproved has_zero_init Peter Lieven
2013-06-20 18:20 ` Peter Lieven [this message]
2013-06-21  9:18   ` [Qemu-devel] [PATCH 1/2] iscsi: add support for bdrv_co_is_allocated() Kevin Wolf
2013-06-21  9:45     ` Peter Lieven
2013-06-21 11:07       ` Kevin Wolf
2013-06-21 11:42         ` Peter Lieven
2013-06-21 13:14           ` Kevin Wolf
2013-06-21 13:23             ` Peter Lieven
2013-06-21 16:31         ` Paolo Bonzini
2013-06-21 17:06           ` Peter Lieven
2013-06-21 17:13             ` ronnie sahlberg
2013-06-21 17:18               ` Peter Lieven
2013-06-21 16:06     ` ronnie sahlberg
2013-06-21 20:01       ` Paolo Bonzini
2013-06-24  8:13     ` Stefan Hajnoczi
2013-06-24 13:49       ` Paolo Bonzini
2013-06-24 16:11         ` Peter Lieven
2013-06-20 18:20 ` [Qemu-devel] [PATCH 2/2] iscsi: add intelligent has_zero_init check Peter Lieven
2013-06-21 20:00   ` Paolo Bonzini
2013-06-21 20:25     ` Peter Lieven
  -- strict thread matches above, loose matches on Subject: below --
2013-06-20 18:08 [Qemu-devel] [PATCH 0/2] iscsi: support for is_allocated and inproved has_zero_init Peter Lieven
2013-06-20 18:08 ` [Qemu-devel] [PATCH 1/2] iscsi: add support for bdrv_co_is_allocated() 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=1371752409-16313-2-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).