coroutine_fn iscsi_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)

{

    IscsiLun *iscsilun = bs->opaque;

    struct IscsiTask iTask;

    struct unmap_list list;

    int r = 0;



    if (!is_byte_request_lun_aligned(offset, bytes, iscsilun)) {

        return -ENOTSUP;

    }



    if (!iscsilun->lbp.lbpu) {

        /* UNMAP is not supported by the target */

        return 0;

    }



    list.lba = offset / iscsilun->block_size;

    list.num = bytes / iscsilun->block_size;



    iscsi_co_init_iscsitask(iscsilun, &iTask);

    qemu_mutex_lock(&iscsilun->mutex);

retry:

    if (iscsi_unmap_task(iscsilun->iscsi, iscsilun->lun, 0, 0, &list, 1,

                         iscsi_co_generic_cb, &iTask) == NULL) {

        r = -ENOMEM;

        goto out_unlock;

    }



    while (!iTask.complete) {

        iscsi_set_events(iscsilun);

        qemu_mutex_unlock(&iscsilun->mutex);

        qemu_coroutine_yield();

        qemu_mutex_lock(&iscsilun->mutex);

    }



    if (iTask.task != NULL) {

        scsi_free_scsi_task(iTask.task);

        iTask.task = NULL;

    }



    if (iTask.do_retry) {

        iTask.complete = 0;

        goto retry;

    }



    if (iTask.status == SCSI_STATUS_CHECK_CONDITION) {

        /* the target might fail with a check condition if it

           is not happy with the alignment of the UNMAP request

           we silently fail in this case */

        goto out_unlock;

    }



    if (iTask.status != SCSI_STATUS_GOOD) {

        r = iTask.err_code;

        goto out_unlock;

    }



    iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,

                               bytes >> BDRV_SECTOR_BITS);



out_unlock:

    qemu_mutex_unlock(&iscsilun->mutex);

    return r;

}

coroutine_fn iscsi_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)

{

    IscsiLun *iscsilun = bs->opaque;

    struct IscsiTask iTask;

    struct unmap_list list;

    int r = 0;



    if (!is_byte_request_lun_aligned(offset, bytes, iscsilun)) {

        return -ENOTSUP;

    }



    if (!iscsilun->lbp.lbpu) {

        

        return 0;

    }



    list.lba = offset / iscsilun->block_size;

    list.num = bytes / iscsilun->block_size;



    iscsi_co_init_iscsitask(iscsilun, &iTask);

    qemu_mutex_lock(&iscsilun->mutex);

retry:

    if (iscsi_unmap_task(iscsilun->iscsi, iscsilun->lun, 0, 0, &list, 1,

                         iscsi_co_generic_cb, &iTask) == NULL) {

        r = -ENOMEM;

        goto out_unlock;

    }



    while (!iTask.complete) {

        iscsi_set_events(iscsilun);

        qemu_mutex_unlock(&iscsilun->mutex);

        qemu_coroutine_yield();

        qemu_mutex_lock(&iscsilun->mutex);

    }



    if (iTask.task != NULL) {

        scsi_free_scsi_task(iTask.task);

        iTask.task = NULL;

    }



    if (iTask.do_retry) {

        iTask.complete = 0;

        goto retry;

    }



    if (iTask.status == SCSI_STATUS_CHECK_CONDITION) {

        





        goto out_unlock;

    }



    if (iTask.status != SCSI_STATUS_GOOD) {

        r = iTask.err_code;

        goto out_unlock;

    }



    iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,

                               bytes >> BDRV_SECTOR_BITS);



out_unlock:

    qemu_mutex_unlock(&iscsilun->mutex);

    return r;

}

    iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,                                bytes >> BDRV_SECTOR_BITS);
coroutine_fn FUNC_0(BlockDriverState *bs, int64_t offset, int bytes)

{

    IscsiLun *iscsilun = bs->opaque;

    struct IscsiTask VAR_0;

    struct unmap_list VAR_1;

    int VAR_2 = 0;



    if (!is_byte_request_lun_aligned(offset, bytes, iscsilun)) {

        return -ENOTSUP;

    }



    if (!iscsilun->lbp.lbpu) {

        

        return 0;

    }



    VAR_1.lba = offset / iscsilun->block_size;

    VAR_1.num = bytes / iscsilun->block_size;



    iscsi_co_init_iscsitask(iscsilun, &VAR_0);

    qemu_mutex_lock(&iscsilun->mutex);

retry:

    if (iscsi_unmap_task(iscsilun->iscsi, iscsilun->lun, 0, 0, &VAR_1, 1,

                         iscsi_co_generic_cb, &VAR_0) == NULL) {

        VAR_2 = -ENOMEM;

        goto out_unlock;

    }



    while (!VAR_0.complete) {

        iscsi_set_events(iscsilun);

        qemu_mutex_unlock(&iscsilun->mutex);

        qemu_coroutine_yield();

        qemu_mutex_lock(&iscsilun->mutex);

    }



    if (VAR_0.task != NULL) {

        scsi_free_scsi_task(VAR_0.task);

        VAR_0.task = NULL;

    }



    if (VAR_0.do_retry) {

        VAR_0.complete = 0;

        goto retry;

    }



    if (VAR_0.status == SCSI_STATUS_CHECK_CONDITION) {

        





        goto out_unlock;

    }



    if (VAR_0.status != SCSI_STATUS_GOOD) {

        VAR_2 = VAR_0.err_code;

        goto out_unlock;

    }



    iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,

                               bytes >> BDRV_SECTOR_BITS);



out_unlock:

    qemu_mutex_unlock(&iscsilun->mutex);

    return VAR_2;

}

coroutine_fn FUNC_0(BlockDriverState *bs, int64_t offset, int bytes)
{ IscsiLun *iscsilun = bs->opaque; struct IscsiTask VAR_0; struct unmap_list VAR_1; int VAR_2 = 0; if (!is_byte_request_lun_aligned(offset, bytes, iscsilun)) { return -ENOTSUP; } if (!iscsilun->lbp.lbpu) { return 0; } VAR_1.lba = offset / iscsilun->block_size; VAR_1.num = bytes / iscsilun->block_size; iscsi_co_init_iscsitask(iscsilun, &VAR_0); qemu_mutex_lock(&iscsilun->mutex); retry:
if (iscsi_unmap_task(iscsilun->iscsi, iscsilun->lun, 0, 0, &VAR_1, 1,
iscsi_co_generic_cb, &VAR_0) == NULL) { VAR_2 = -ENOMEM; goto out_unlock; } while (!VAR_0.complete) { iscsi_set_events(iscsilun); qemu_mutex_unlock(&iscsilun->mutex); qemu_coroutine_yield(); qemu_mutex_lock(&iscsilun->mutex); } if (VAR_0.task != NULL) { scsi_free_scsi_task(VAR_0.task); VAR_0.task = NULL; } if (VAR_0.do_retry) { VAR_0.complete = 0; goto retry; } if (VAR_0.status == SCSI_STATUS_CHECK_CONDITION) { goto out_unlock; } if (VAR_0.status != SCSI_STATUS_GOOD) { VAR_2 = VAR_0.err_code; goto out_unlock; } iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,
bytes >> BDRV_SECTOR_BITS); out_unlock:
qemu_mutex_unlock(&iscsilun->mutex); return VAR_2; }