From: Stefan Weil <sw@weilnetz.de>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Lieven <pl@kamp.de>,
qemu-devel@nongnu.org, Anthony Liguori <anthony@codemonkey.ws>
Subject: Re: [Qemu-devel] [PULL 08/11] iscsi: add .bdrv_get_block_status
Date: Tue, 17 Sep 2013 19:18:45 +0200 [thread overview]
Message-ID: <52388EF5.4030108@weilnetz.de> (raw)
In-Reply-To: <1378984634-765-9-git-send-email-pbonzini@redhat.com>
Am 12.09.2013 13:17, schrieb Paolo Bonzini:
> From: Peter Lieven <pl@kamp.de>
>
> this patch adds a coroutine for .bdrv_co_block_status as well as
> a generic framework that can be used to build coroutines in block/iscsi.
>
> Signed-off-by: Peter Lieven <pl@kamp.de>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> block/iscsi.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 136 insertions(+)
>
> diff --git a/block/iscsi.c b/block/iscsi.c
> index bfd659a..c377d21 100644
> --- a/block/iscsi.c
> +++ b/block/iscsi.c
> @@ -58,6 +58,15 @@ typedef struct IscsiLun {
> struct scsi_inquiry_block_limits bl;
> } IscsiLun;
>
> +typedef struct IscsiTask {
> + int status;
> + int complete;
> + int retries;
> + int do_retry;
> + struct scsi_task *task;
> + Coroutine *co;
> +} IscsiTask;
> +
> typedef struct IscsiAIOCB {
> BlockDriverAIOCB common;
> QEMUIOVector *qiov;
> @@ -111,6 +120,41 @@ iscsi_schedule_bh(IscsiAIOCB *acb)
> qemu_bh_schedule(acb->bh);
> }
>
> +static void
> +iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
> + void *command_data, void *opaque)
> +{
> + struct IscsiTask *iTask = opaque;
> + struct scsi_task *task = command_data;
> +
> + iTask->complete = 1;
> + iTask->status = status;
> + iTask->do_retry = 0;
> + iTask->task = task;
> +
> + if (iTask->retries-- > 0 && status == SCSI_STATUS_CHECK_CONDITION
> + && task->sense.key == SCSI_SENSE_UNIT_ATTENTION) {
> + iTask->do_retry = 1;
> + goto out;
> + }
> +
> + if (status != SCSI_STATUS_GOOD) {
> + error_report("iSCSI: Failure. %s", iscsi_get_error(iscsi));
> + }
> +
> +out:
> + if (iTask->co) {
> + qemu_coroutine_enter(iTask->co, NULL);
> + }
> +}
> +
> +static void iscsi_co_init_iscsitask(IscsiLun *iscsilun, struct IscsiTask *iTask)
> +{
> + *iTask = (struct IscsiTask) {
> + .co = qemu_coroutine_self(),
> + .retries = ISCSI_CMD_RETRIES,
> + };
> +}
>
> static void
> iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void *command_data,
> @@ -848,6 +892,96 @@ iscsi_getlength(BlockDriverState *bs)
> return len;
> }
>
> +static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs,
> + int64_t sector_num,
> + int nb_sectors, int *pnum)
> +{
> + IscsiLun *iscsilun = bs->opaque;
> + struct scsi_get_lba_status *lbas = NULL;
> + struct scsi_lba_status_descriptor *lbasd = NULL;
> + struct IscsiTask iTask;
> + int64_t ret;
> +
> + iscsi_co_init_iscsitask(iscsilun, &iTask);
> +
> + if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
> + ret = -EINVAL;
> + goto out;
> + }
> +
> + /* default to all sectors allocated */
> + ret = BDRV_BLOCK_DATA;
> + ret |= (sector_num << BDRV_SECTOR_BITS) | BDRV_BLOCK_OFFSET_VALID;
> + *pnum = nb_sectors;
> +
> + /* LUN does not support logical block provisioning */
> + if (iscsilun->lbpme == 0) {
> + goto out;
> + }
> +
> +retry:
> + if (iscsi_get_lba_status_task(iscsilun->iscsi, iscsilun->lun,
> + sector_qemu2lun(sector_num, iscsilun),
> + 8 + 16, iscsi_co_generic_cb,
> + &iTask) == NULL) {
> + ret = -EIO;
> + goto out;
> + }
> +
> + while (!iTask.complete) {
> + iscsi_set_events(iscsilun);
> + qemu_coroutine_yield();
> + }
> +
> + if (iTask.do_retry) {
> + if (iTask.task != NULL) {
> + scsi_free_scsi_task(iTask.task);
> + iTask.task = NULL;
> + }
> + goto retry;
> + }
> +
> + if (iTask.status != SCSI_STATUS_GOOD) {
> + /* in case the get_lba_status_callout fails (i.e.
> + * because the device is busy or the cmd is not
> + * supported) we pretend all blocks are allocated
> + * for backwards compatiblity */
> + goto out;
> + }
> +
> + lbas = scsi_datain_unmarshall(iTask.task);
> + if (lbas == NULL) {
> + ret = -EIO;
> + goto out;
> + }
> +
> + lbasd = &lbas->descriptors[0];
> +
> + if (sector_qemu2lun(sector_num, iscsilun) != lbasd->lba) {
> + ret = -EIO;
> + goto out;
> + }
> +
> + *pnum = sector_lun2qemu(lbasd->num_blocks, iscsilun);
> + if (*pnum > nb_sectors) {
> + *pnum = nb_sectors;
> + }
> +
> + if (lbasd->provisioning == SCSI_PROVISIONING_TYPE_DEALLOCATED ||
> + lbasd->provisioning == SCSI_PROVISIONING_TYPE_ANCHORED) {
> + ret &= ~BDRV_BLOCK_DATA;
> + if (iscsilun->lbprz) {
> + ret |= BDRV_BLOCK_ZERO;
> + }
> + }
> +
> +out:
> + if (iTask.task != NULL) {
> + scsi_free_scsi_task(iTask.task);
> + }
> + return ret;
> +}
> +
> static int parse_chap(struct iscsi_context *iscsi, const char *target)
> {
> QemuOptsList *list;
> @@ -1398,6 +1532,8 @@ static BlockDriver bdrv_iscsi = {
> .bdrv_getlength = iscsi_getlength,
> .bdrv_truncate = iscsi_truncate,
>
> + .bdrv_co_get_block_status = iscsi_co_get_block_status,
> +
> .bdrv_aio_readv = iscsi_aio_readv,
> .bdrv_aio_writev = iscsi_aio_writev,
> .bdrv_aio_flush = iscsi_aio_flush,
Latest QEMU git is broken on Debian wheezy:
block/iscsi.c: In function ‘iscsi_co_get_block_status’:
block/iscsi.c:842:5: error: implicit declaration of function
‘iscsi_get_lba_status_task’ [-Werror=implicit-function-declaration]
block/iscsi.c:842:5: error: nested extern declaration of
‘iscsi_get_lba_status_task’ [-Werror=nested-externs]
block/iscsi.c:845:43: error: comparison between pointer and integer
[-Werror]
block/iscsi.c:877:18: error: dereferencing pointer to incomplete type
block/iscsi.c:879:55: error: dereferencing pointer to incomplete type
block/iscsi.c:884:34: error: dereferencing pointer to incomplete type
block/iscsi.c:889:14: error: dereferencing pointer to incomplete type
block/iscsi.c:889:32: error: ‘SCSI_PROVISIONING_TYPE_DEALLOCATED’
undeclared (first use in this function)
block/iscsi.c:889:32: note: each undeclared identifier is reported only
once for each function it appears in
block/iscsi.c:890:14: error: dereferencing pointer to incomplete type
block/iscsi.c:890:32: error: ‘SCSI_PROVISIONING_TYPE_ANCHORED’
undeclared (first use in this function)
cc1: all warnings being treated as errors
Debian includes libiscsi-dev 1.4.0 without a libiscsi.pk, so it uses a
compile test
which thinks that libiscsi is good enough.
Did the latest changes raise the requirements for libscsi?
Regards,
Stefan
next prev parent reply other threads:[~2013-09-17 17:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-12 11:17 [Qemu-devel] [PULL 00/11] SCSI patches for 2013-09-11 Paolo Bonzini
2013-09-12 11:17 ` [Qemu-devel] [PULL 01/11] scsi: prefer UUID to VM name for the initiator name Paolo Bonzini
2013-09-12 11:17 ` [Qemu-devel] [PULL 02/11] spapr-vscsi: add task management Paolo Bonzini
2013-09-12 11:17 ` [Qemu-devel] [PULL 03/11] virtio-scsi: Make type virtio-scsi-common abstract Paolo Bonzini
2013-09-12 11:17 ` [Qemu-devel] [PULL 04/11] scsi: Fix scsi_bus_legacy_add_drive() scsi-generic with serial Paolo Bonzini
2013-09-12 11:17 ` [Qemu-devel] [PULL 05/11] hw/scsi/lsi53c895a: Use sextract32 for sign-extension Paolo Bonzini
2013-09-12 11:17 ` [Qemu-devel] [PULL 06/11] hw/scsi/lsi53c895a: Use deposit32 rather than handcoded shift/mask Paolo Bonzini
2013-09-12 11:17 ` [Qemu-devel] [PULL 07/11] iscsi: add logical block provisioning information to iscsilun Paolo Bonzini
2013-09-12 11:17 ` [Qemu-devel] [PULL 08/11] iscsi: add .bdrv_get_block_status Paolo Bonzini
2013-09-17 17:18 ` Stefan Weil [this message]
2013-09-17 17:21 ` Paolo Bonzini
2013-09-19 7:24 ` Peter Lieven
2013-09-19 13:46 ` Paolo Bonzini
2013-10-02 11:37 ` Peter Lieven
2013-09-12 11:17 ` [Qemu-devel] [PULL 09/11] iscsi: split discard requests in multiple parts Paolo Bonzini
2013-09-12 11:17 ` [Qemu-devel] [PULL 10/11] spapr-vscsi: Adding VSCSI capabilities Paolo Bonzini
2013-09-12 11:17 ` [Qemu-devel] [PULL 11/11] spapr-vscsi: Report error on unsupported MAD requests Paolo Bonzini
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=52388EF5.4030108@weilnetz.de \
--to=sw@weilnetz.de \
--cc=anthony@codemonkey.ws \
--cc=pbonzini@redhat.com \
--cc=pl@kamp.de \
--cc=qemu-devel@nongnu.org \
/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.