From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43578) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzlZb-0002Zc-4g for qemu-devel@nongnu.org; Thu, 18 Jul 2013 06:36:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UzlZZ-0004yS-1C for qemu-devel@nongnu.org; Thu, 18 Jul 2013 06:36:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7343) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzlZY-0004yL-PV for qemu-devel@nongnu.org; Thu, 18 Jul 2013 06:36:32 -0400 Message-ID: <51E7C520.6040005@redhat.com> Date: Thu, 18 Jul 2013 12:36:16 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1374135551-22401-1-git-send-email-pl@kamp.de> <1374135551-22401-3-git-send-email-pl@kamp.de> In-Reply-To: <1374135551-22401-3-git-send-email-pl@kamp.de> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCHv4 2/2] iscsi: add .bdrv_co_is_allocated List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Lieven Cc: kwolf@redhat.com, ronniesahlberg@gmail.com, qemu-devel@nongnu.org, stefanha@redhat.com Il 18/07/2013 10:19, Peter Lieven ha scritto: > this patch adds a coroutine for .bdrv_co_is_allocated as well as > a generic framework that can be used to build coroutines in block/iscsi. This conflicts with my bdrv_get_block_status patches. Paolo > Signed-off-by: Peter Lieven > --- > block/iscsi.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 130 insertions(+) > > diff --git a/block/iscsi.c b/block/iscsi.c > index ab42f1e..56dedff 100644 > --- a/block/iscsi.c > +++ b/block/iscsi.c > @@ -55,6 +55,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; > @@ -110,6 +119,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, > @@ -804,6 +848,90 @@ 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_get_lba_status *lbas = NULL; > + struct scsi_lba_status_descriptor *lbasd = NULL; > + struct IscsiTask iTask; > + int ret; > + > + /* default to all sectors allocated */ > + ret = 1; > + *pnum = nb_sectors; > + > + /* LUN does not support logical block provisioning */ > + if (iscsilun->lbpme == 0) { > + goto out; > + } > + > + iscsi_co_init_iscsitask(iscsilun, &iTask); > + > +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 = 0; > + *pnum = 0; > + 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 = 0; > + *pnum = 0; > + goto out; > + } > + > + lbasd = &lbas->descriptors[0]; > + > + if (sector_qemu2lun(sector_num, iscsilun) != lbasd->lba) { > + ret = 0; > + *pnum = 0; > + goto out; > + } > + > + *pnum = lbasd->num_blocks * (iscsilun->block_size / BDRV_SECTOR_SIZE); > + if (*pnum > nb_sectors) { > + *pnum = nb_sectors; > + } > + > + if (lbasd->provisioning == SCSI_PROVISIONING_TYPE_DEALLOCATED || > + lbasd->provisioning == SCSI_PROVISIONING_TYPE_ANCHORED) { > + ret = 0; > + } > + > +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; > @@ -1345,6 +1473,8 @@ static BlockDriver bdrv_iscsi = { > .bdrv_getlength = iscsi_getlength, > .bdrv_truncate = iscsi_truncate, > > + .bdrv_co_is_allocated = iscsi_co_is_allocated, > + > .bdrv_aio_readv = iscsi_aio_readv, > .bdrv_aio_writev = iscsi_aio_writev, > .bdrv_aio_flush = iscsi_aio_flush, >