static int scsi_qdev_init(DeviceState *qdev)

{

    SCSIDevice *dev = SCSI_DEVICE(qdev);

    SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);

    SCSIDevice *d;

    int rc = -1;



    if (dev->channel > bus->info->max_channel) {

        error_report("bad scsi channel id: %d", dev->channel);

        goto err;

    }

    if (dev->id != -1 && dev->id > bus->info->max_target) {

        error_report("bad scsi device id: %d", dev->id);

        goto err;

    }

    if (dev->lun != -1 && dev->lun > bus->info->max_lun) {

        error_report("bad scsi device lun: %d", dev->lun);

        goto err;

    }



    if (dev->id == -1) {

        int id = -1;

        if (dev->lun == -1) {

            dev->lun = 0;

        }

        do {

            d = scsi_device_find(bus, dev->channel, ++id, dev->lun);

        } while (d && d->lun == dev->lun && id < bus->info->max_target);

        if (d && d->lun == dev->lun) {

            error_report("no free target");

            goto err;

        }

        dev->id = id;

    } else if (dev->lun == -1) {

        int lun = -1;

        do {

            d = scsi_device_find(bus, dev->channel, dev->id, ++lun);

        } while (d && d->lun == lun && lun < bus->info->max_lun);

        if (d && d->lun == lun) {

            error_report("no free lun");

            goto err;

        }

        dev->lun = lun;

    } else {

        d = scsi_device_find(bus, dev->channel, dev->id, dev->lun);

        assert(d);

        if (d->lun == dev->lun && dev != d) {

            error_report("lun already used by '%s'", d->qdev.id);

            goto err;

        }

    }



    QTAILQ_INIT(&dev->requests);

    rc = scsi_device_init(dev);

    if (rc == 0) {

        dev->vmsentry = qemu_add_vm_change_state_handler(scsi_dma_restart_cb,

                                                         dev);

    }



    if (bus->info->hotplug) {

        bus->info->hotplug(bus, dev);

    }



err:

    return rc;

}

static int scsi_qdev_init(DeviceState *qdev)

{

    SCSIDevice *dev = SCSI_DEVICE(qdev);

    SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);

    SCSIDevice *d;

    int rc = -1;



    if (dev->channel > bus->info->max_channel) {

        error_report("bad scsi channel id: %d", dev->channel);

        goto err;

    }

    if (dev->id != -1 && dev->id > bus->info->max_target) {

        error_report("bad scsi device id: %d", dev->id);

        goto err;

    }

    if (dev->lun != -1 && dev->lun > bus->info->max_lun) {

        error_report("bad scsi device lun: %d", dev->lun);

        goto err;

    }



    if (dev->id == -1) {

        int id = -1;

        if (dev->lun == -1) {

            dev->lun = 0;

        }

        do {

            d = scsi_device_find(bus, dev->channel, ++id, dev->lun);

        } while (d && d->lun == dev->lun && id < bus->info->max_target);

        if (d && d->lun == dev->lun) {

            error_report("no free target");

            goto err;

        }

        dev->id = id;

    } else if (dev->lun == -1) {

        int lun = -1;

        do {

            d = scsi_device_find(bus, dev->channel, dev->id, ++lun);

        } while (d && d->lun == lun && lun < bus->info->max_lun);

        if (d && d->lun == lun) {

            error_report("no free lun");

            goto err;

        }

        dev->lun = lun;

    } else {

        d = scsi_device_find(bus, dev->channel, dev->id, dev->lun);

        assert(d);

        if (d->lun == dev->lun && dev != d) {

            error_report("lun already used by '%s'", d->qdev.id);

            goto err;

        }

    }



    QTAILQ_INIT(&dev->requests);

    rc = scsi_device_init(dev);

    if (rc == 0) {

        dev->vmsentry = qemu_add_vm_change_state_handler(scsi_dma_restart_cb,

                                                         dev);

    }



    if (bus->info->hotplug) {

        bus->info->hotplug(bus, dev);

    }



err:

    return rc;

}

static int FUNC_0(DeviceState *VAR_0)

{

    SCSIDevice *dev = SCSI_DEVICE(VAR_0);

    SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->VAR_0.parent_bus);

    SCSIDevice *d;

    int VAR_1 = -1;



    if (dev->channel > bus->info->max_channel) {

        error_report("bad scsi channel VAR_2: %d", dev->channel);

        goto err;

    }

    if (dev->VAR_2 != -1 && dev->VAR_2 > bus->info->max_target) {

        error_report("bad scsi device VAR_2: %d", dev->VAR_2);

        goto err;

    }

    if (dev->VAR_3 != -1 && dev->VAR_3 > bus->info->max_lun) {

        error_report("bad scsi device VAR_3: %d", dev->VAR_3);

        goto err;

    }



    if (dev->VAR_2 == -1) {

        int VAR_2 = -1;

        if (dev->VAR_3 == -1) {

            dev->VAR_3 = 0;

        }

        do {

            d = scsi_device_find(bus, dev->channel, ++VAR_2, dev->VAR_3);

        } while (d && d->VAR_3 == dev->VAR_3 && VAR_2 < bus->info->max_target);

        if (d && d->VAR_3 == dev->VAR_3) {

            error_report("no free target");

            goto err;

        }

        dev->VAR_2 = VAR_2;

    } else if (dev->VAR_3 == -1) {

        int VAR_3 = -1;

        do {

            d = scsi_device_find(bus, dev->channel, dev->VAR_2, ++VAR_3);

        } while (d && d->VAR_3 == VAR_3 && VAR_3 < bus->info->max_lun);

        if (d && d->VAR_3 == VAR_3) {

            error_report("no free VAR_3");

            goto err;

        }

        dev->VAR_3 = VAR_3;

    } else {

        d = scsi_device_find(bus, dev->channel, dev->VAR_2, dev->VAR_3);

        assert(d);

        if (d->VAR_3 == dev->VAR_3 && dev != d) {

            error_report("VAR_3 already used by '%s'", d->VAR_0.VAR_2);

            goto err;

        }

    }



    QTAILQ_INIT(&dev->requests);

    VAR_1 = scsi_device_init(dev);

    if (VAR_1 == 0) {

        dev->vmsentry = qemu_add_vm_change_state_handler(scsi_dma_restart_cb,

                                                         dev);

    }



    if (bus->info->hotplug) {

        bus->info->hotplug(bus, dev);

    }



err:

    return VAR_1;

}

static int FUNC_0(DeviceState *VAR_0)
{ SCSIDevice *dev = SCSI_DEVICE(VAR_0); SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->VAR_0.parent_bus); SCSIDevice *d; int VAR_1 = -1; if (dev->channel > bus->info->max_channel) { error_report("bad scsi channel VAR_2: %d", dev->channel); goto err; } if (dev->VAR_2 != -1 && dev->VAR_2 > bus->info->max_target) { error_report("bad scsi device VAR_2: %d", dev->VAR_2); goto err; } if (dev->VAR_3 != -1 && dev->VAR_3 > bus->info->max_lun) { error_report("bad scsi device VAR_3: %d", dev->VAR_3); goto err; } if (dev->VAR_2 == -1) { int VAR_2 = -1; if (dev->VAR_3 == -1) { dev->VAR_3 = 0; } do { d = scsi_device_find(bus, dev->channel, ++VAR_2, dev->VAR_3); } while (d && d->VAR_3 == dev->VAR_3 && VAR_2 < bus->info->max_target); if (d && d->VAR_3 == dev->VAR_3) { error_report("no free target"); goto err; } dev->VAR_2 = VAR_2; } else if (dev->VAR_3 == -1) { int VAR_3 = -1; do { d = scsi_device_find(bus, dev->channel, dev->VAR_2, ++VAR_3); } while (d && d->VAR_3 == VAR_3 && VAR_3 < bus->info->max_lun); if (d && d->VAR_3 == VAR_3) { error_report("no free VAR_3"); goto err; } dev->VAR_3 = VAR_3; } else { d = scsi_device_find(bus, dev->channel, dev->VAR_2, dev->VAR_3); assert(d); if (d->VAR_3 == dev->VAR_3 && dev != d) { error_report("VAR_3 already used by '%s'", d->VAR_0.VAR_2); goto err; } } QTAILQ_INIT(&dev->requests); VAR_1 = scsi_device_init(dev); if (VAR_1 == 0) { dev->vmsentry = qemu_add_vm_change_state_handler(scsi_dma_restart_cb,
dev); } if (bus->info->hotplug) { bus->info->hotplug(bus, dev); } err:
return VAR_1; }