static int iscsi_readcapacity_sync(IscsiLun *iscsilun)

{

    struct scsi_task *task = NULL;

    struct scsi_readcapacity10 *rc10 = NULL;

    struct scsi_readcapacity16 *rc16 = NULL;

    int ret = 0;

    int retries = ISCSI_CMD_RETRIES; 



    do {

        if (task != NULL) {

            scsi_free_scsi_task(task);

            task = NULL;

        }



        switch (iscsilun->type) {

        case TYPE_DISK:

            task = iscsi_readcapacity16_sync(iscsilun->iscsi, iscsilun->lun);

            if (task != NULL && task->status == SCSI_STATUS_GOOD) {

                rc16 = scsi_datain_unmarshall(task);

                if (rc16 == NULL) {

                    error_report("iSCSI: Failed to unmarshall readcapacity16 data.");

                    ret = -EINVAL;

                } else {

                    iscsilun->block_size = rc16->block_length;

                    iscsilun->num_blocks = rc16->returned_lba + 1;

                    iscsilun->lbpme = rc16->lbpme;

                    iscsilun->lbprz = rc16->lbprz;

                }

            }

            break;

        case TYPE_ROM:

            task = iscsi_readcapacity10_sync(iscsilun->iscsi, iscsilun->lun, 0, 0);

            if (task != NULL && task->status == SCSI_STATUS_GOOD) {

                rc10 = scsi_datain_unmarshall(task);

                if (rc10 == NULL) {

                    error_report("iSCSI: Failed to unmarshall readcapacity10 data.");

                    ret = -EINVAL;

                } else {

                    iscsilun->block_size = rc10->block_size;

                    if (rc10->lba == 0) {

                        /* blank disk loaded */

                        iscsilun->num_blocks = 0;

                    } else {

                        iscsilun->num_blocks = rc10->lba + 1;

                    }

                }

            }

            break;

        default:

            return 0;

        }

    } while (task != NULL && task->status == SCSI_STATUS_CHECK_CONDITION

             && task->sense.key == SCSI_SENSE_UNIT_ATTENTION

             && retries-- > 0);



    if (task == NULL || task->status != SCSI_STATUS_GOOD) {

        error_report("iSCSI: failed to send readcapacity10 command.");

        ret = -EINVAL;

    }

    if (task) {

        scsi_free_scsi_task(task);

    }

    return ret;

}

static int iscsi_readcapacity_sync(IscsiLun *iscsilun)

{

    struct scsi_task *task = NULL;

    struct scsi_readcapacity10 *rc10 = NULL;

    struct scsi_readcapacity16 *rc16 = NULL;

    int ret = 0;

    int retries = ISCSI_CMD_RETRIES; 



    do {

        if (task != NULL) {

            scsi_free_scsi_task(task);

            task = NULL;

        }



        switch (iscsilun->type) {

        case TYPE_DISK:

            task = iscsi_readcapacity16_sync(iscsilun->iscsi, iscsilun->lun);

            if (task != NULL && task->status == SCSI_STATUS_GOOD) {

                rc16 = scsi_datain_unmarshall(task);

                if (rc16 == NULL) {

                    error_report("iSCSI: Failed to unmarshall readcapacity16 data.");

                    ret = -EINVAL;

                } else {

                    iscsilun->block_size = rc16->block_length;

                    iscsilun->num_blocks = rc16->returned_lba + 1;

                    iscsilun->lbpme = rc16->lbpme;

                    iscsilun->lbprz = rc16->lbprz;

                }

            }

            break;

        case TYPE_ROM:

            task = iscsi_readcapacity10_sync(iscsilun->iscsi, iscsilun->lun, 0, 0);

            if (task != NULL && task->status == SCSI_STATUS_GOOD) {

                rc10 = scsi_datain_unmarshall(task);

                if (rc10 == NULL) {

                    error_report("iSCSI: Failed to unmarshall readcapacity10 data.");

                    ret = -EINVAL;

                } else {

                    iscsilun->block_size = rc10->block_size;

                    if (rc10->lba == 0) {

                        

                        iscsilun->num_blocks = 0;

                    } else {

                        iscsilun->num_blocks = rc10->lba + 1;

                    }

                }

            }

            break;

        default:

            return 0;

        }

    } while (task != NULL && task->status == SCSI_STATUS_CHECK_CONDITION

             && task->sense.key == SCSI_SENSE_UNIT_ATTENTION

             && retries-- > 0);



    if (task == NULL || task->status != SCSI_STATUS_GOOD) {

        error_report("iSCSI: failed to send readcapacity10 command.");

        ret = -EINVAL;

    }

    if (task) {

        scsi_free_scsi_task(task);

    }

    return ret;

}

            return 0; static int iscsi_readcapacity_sync(IscsiLun *iscsilun)     int ret = 0;                     error_report("iSCSI: Failed to unmarshall readcapacity16 data.");                     ret = -EINVAL;                     error_report("iSCSI: Failed to unmarshall readcapacity10 data.");                     ret = -EINVAL;             return 0;         error_report("iSCSI: failed to send readcapacity10 command.");         ret = -EINVAL;     return ret;     int ret = 0;
static int FUNC_0(IscsiLun *VAR_0)

{

    struct scsi_task *VAR_1 = NULL;

    struct scsi_readcapacity10 *VAR_2 = NULL;

    struct scsi_readcapacity16 *VAR_3 = NULL;

    int VAR_4 = 0;

    int VAR_5 = ISCSI_CMD_RETRIES; 



    do {

        if (VAR_1 != NULL) {

            scsi_free_scsi_task(VAR_1);

            VAR_1 = NULL;

        }



        switch (VAR_0->type) {

        case TYPE_DISK:

            VAR_1 = iscsi_readcapacity16_sync(VAR_0->iscsi, VAR_0->lun);

            if (VAR_1 != NULL && VAR_1->status == SCSI_STATUS_GOOD) {

                VAR_3 = scsi_datain_unmarshall(VAR_1);

                if (VAR_3 == NULL) {

                    error_report("iSCSI: Failed to unmarshall readcapacity16 data.");

                    VAR_4 = -EINVAL;

                } else {

                    VAR_0->block_size = VAR_3->block_length;

                    VAR_0->num_blocks = VAR_3->returned_lba + 1;

                    VAR_0->lbpme = VAR_3->lbpme;

                    VAR_0->lbprz = VAR_3->lbprz;

                }

            }

            break;

        case TYPE_ROM:

            VAR_1 = iscsi_readcapacity10_sync(VAR_0->iscsi, VAR_0->lun, 0, 0);

            if (VAR_1 != NULL && VAR_1->status == SCSI_STATUS_GOOD) {

                VAR_2 = scsi_datain_unmarshall(VAR_1);

                if (VAR_2 == NULL) {

                    error_report("iSCSI: Failed to unmarshall readcapacity10 data.");

                    VAR_4 = -EINVAL;

                } else {

                    VAR_0->block_size = VAR_2->block_size;

                    if (VAR_2->lba == 0) {

                        

                        VAR_0->num_blocks = 0;

                    } else {

                        VAR_0->num_blocks = VAR_2->lba + 1;

                    }

                }

            }

            break;

        default:

            return 0;

        }

    } while (VAR_1 != NULL && VAR_1->status == SCSI_STATUS_CHECK_CONDITION

             && VAR_1->sense.key == SCSI_SENSE_UNIT_ATTENTION

             && VAR_5-- > 0);



    if (VAR_1 == NULL || VAR_1->status != SCSI_STATUS_GOOD) {

        error_report("iSCSI: failed to send readcapacity10 command.");

        VAR_4 = -EINVAL;

    }

    if (VAR_1) {

        scsi_free_scsi_task(VAR_1);

    }

    return VAR_4;

}

static int FUNC_0(IscsiLun *VAR_0)
{ struct scsi_task *VAR_1 = NULL; struct scsi_readcapacity10 *VAR_2 = NULL; struct scsi_readcapacity16 *VAR_3 = NULL; int VAR_4 = 0; int VAR_5 = ISCSI_CMD_RETRIES; do { if (VAR_1 != NULL) { scsi_free_scsi_task(VAR_1); VAR_1 = NULL; } switch (VAR_0->type) { case TYPE_DISK:
VAR_1 = iscsi_readcapacity16_sync(VAR_0->iscsi, VAR_0->lun); if (VAR_1 != NULL && VAR_1->status == SCSI_STATUS_GOOD) { VAR_3 = scsi_datain_unmarshall(VAR_1); if (VAR_3 == NULL) { error_report("iSCSI: Failed to unmarshall readcapacity16 data."); VAR_4 = -EINVAL; } else { VAR_0->block_size = VAR_3->block_length; VAR_0->num_blocks = VAR_3->returned_lba + 1; VAR_0->lbpme = VAR_3->lbpme; VAR_0->lbprz = VAR_3->lbprz; } } break; case TYPE_ROM:
VAR_1 = iscsi_readcapacity10_sync(VAR_0->iscsi, VAR_0->lun, 0, 0); if (VAR_1 != NULL && VAR_1->status == SCSI_STATUS_GOOD) { VAR_2 = scsi_datain_unmarshall(VAR_1); if (VAR_2 == NULL) { error_report("iSCSI: Failed to unmarshall readcapacity10 data."); VAR_4 = -EINVAL; } else { VAR_0->block_size = VAR_2->block_size; if (VAR_2->lba == 0) { VAR_0->num_blocks = 0; } else { VAR_0->num_blocks = VAR_2->lba + 1; } } } break; default:
return 0; } } while (VAR_1 != NULL && VAR_1->status == SCSI_STATUS_CHECK_CONDITION && VAR_1->sense.key == SCSI_SENSE_UNIT_ATTENTION
&& VAR_5-- > 0); if (VAR_1 == NULL || VAR_1->status != SCSI_STATUS_GOOD) { error_report("iSCSI: failed to send readcapacity10 command."); VAR_4 = -EINVAL; } if (VAR_1) { scsi_free_scsi_task(VAR_1); } return VAR_4; }