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

{

    IscsiLun *iscsilun = bs->opaque;

    struct IscsiTask iTask;

    struct unmap_list list;



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

        return -ENOTSUP;

    }



    if (!iscsilun->lbp.lbpu) {

        /* UNMAP is not supported by the target */

        return 0;

    }



    list.lba = offset / iscsilun->block_size;

    list.num = count / iscsilun->block_size;



    iscsi_co_init_iscsitask(iscsilun, &iTask);

retry:

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

                         iscsi_co_generic_cb, &iTask) == NULL) {

        return -ENOMEM;

    }



    while (!iTask.complete) {

        iscsi_set_events(iscsilun);

        qemu_coroutine_yield();

    }



    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 */

        return 0;

    }



    if (iTask.status != SCSI_STATUS_GOOD) {

        return iTask.err_code;

    }



    iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,

                               count >> BDRV_SECTOR_BITS);



    return 0;

}

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

{

    IscsiLun *iscsilun = bs->opaque;

    struct IscsiTask iTask;

    struct unmap_list list;



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

        return -ENOTSUP;

    }



    if (!iscsilun->lbp.lbpu) {

        

        return 0;

    }



    list.lba = offset / iscsilun->block_size;

    list.num = count / iscsilun->block_size;



    iscsi_co_init_iscsitask(iscsilun, &iTask);

retry:

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

                         iscsi_co_generic_cb, &iTask) == NULL) {

        return -ENOMEM;

    }



    while (!iTask.complete) {

        iscsi_set_events(iscsilun);

        qemu_coroutine_yield();

    }



    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) {

        





        return 0;

    }



    if (iTask.status != SCSI_STATUS_GOOD) {

        return iTask.err_code;

    }



    iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,

                               count >> BDRV_SECTOR_BITS);



    return 0;

}

coroutine_fn FUNC_0(BlockDriverState *bs, int64_t offset, int count)

{

    IscsiLun *iscsilun = bs->opaque;

    struct IscsiTask VAR_0;

    struct unmap_list VAR_1;



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

        return -ENOTSUP;

    }



    if (!iscsilun->lbp.lbpu) {

        

        return 0;

    }



    VAR_1.lba = offset / iscsilun->block_size;

    VAR_1.num = count / iscsilun->block_size;



    iscsi_co_init_iscsitask(iscsilun, &VAR_0);

retry:

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

                         iscsi_co_generic_cb, &VAR_0) == NULL) {

        return -ENOMEM;

    }



    while (!VAR_0.complete) {

        iscsi_set_events(iscsilun);

        qemu_coroutine_yield();

    }



    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) {

        





        return 0;

    }



    if (VAR_0.status != SCSI_STATUS_GOOD) {

        return VAR_0.err_code;

    }



    iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,

                               count >> BDRV_SECTOR_BITS);



    return 0;

}

coroutine_fn FUNC_0(BlockDriverState *bs, int64_t offset, int count)
{ IscsiLun *iscsilun = bs->opaque; struct IscsiTask VAR_0; struct unmap_list VAR_1; if (!is_byte_request_lun_aligned(offset, count, iscsilun)) { return -ENOTSUP; } if (!iscsilun->lbp.lbpu) { return 0; } VAR_1.lba = offset / iscsilun->block_size; VAR_1.num = count / iscsilun->block_size; iscsi_co_init_iscsitask(iscsilun, &VAR_0); retry:
if (iscsi_unmap_task(iscsilun->iscsi, iscsilun->lun, 0, 0, &VAR_1, 1,
iscsi_co_generic_cb, &VAR_0) == NULL) { return -ENOMEM; } while (!VAR_0.complete) { iscsi_set_events(iscsilun); qemu_coroutine_yield(); } 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) { return 0; } if (VAR_0.status != SCSI_STATUS_GOOD) { return VAR_0.err_code; } iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS,
count >> BDRV_SECTOR_BITS); return 0; }