static int vscsi_queue_cmd(VSCSIState *s, vscsi_req *req)

{

    union srp_iu *srp = &req->iu.srp;

    SCSIDevice *sdev;

    int n, id, lun;



    vscsi_decode_id_lun(be64_to_cpu(srp->cmd.lun), &id, &lun);



    /* Qemu vs. linux issue with LUNs to be sorted out ... */

    sdev = (id < 8 && lun < 16) ? s->bus.devs[id] : NULL;

    if (!sdev) {

        dprintf("VSCSI: Command for id %d with no drive\n", id);

        if (srp->cmd.cdb[0] == INQUIRY) {

            vscsi_inquiry_no_target(s, req);

        } else {

            vscsi_makeup_sense(s, req, ILLEGAL_REQUEST, 0x24, 0x00);

            vscsi_send_rsp(s, req, CHECK_CONDITION, 0, 0);

        } return 1;

    }



    req->sdev = sdev;

    req->lun = lun;

    n = sdev->info->send_command(sdev, req->qtag, srp->cmd.cdb, lun);



    dprintf("VSCSI: Queued command tag 0x%x CMD 0x%x ID %d LUN %d ret: %d\n",

            req->qtag, srp->cmd.cdb[0], id, lun, n);



    if (n) {

        /* Transfer direction must be set before preprocessing the

         * descriptors

         */

        req->writing = (n < 1);



        /* Preprocess RDMA descriptors */

        vscsi_preprocess_desc(req);

    }



    /* Get transfer direction and initiate transfer */

    if (n > 0) {

        req->data_len = n;

        sdev->info->read_data(sdev, req->qtag);

    } else if (n < 0) {

        req->data_len = -n;

        sdev->info->write_data(sdev, req->qtag);

    }

    /* Don't touch req here, it may have been recycled already */



    return 0;

}

static int vscsi_queue_cmd(VSCSIState *s, vscsi_req *req)

{

    union srp_iu *srp = &req->iu.srp;

    SCSIDevice *sdev;

    int n, id, lun;



    vscsi_decode_id_lun(be64_to_cpu(srp->cmd.lun), &id, &lun);



    

    sdev = (id < 8 && lun < 16) ? s->bus.devs[id] : NULL;

    if (!sdev) {

        dprintf("VSCSI: Command for id %d with no drive\n", id);

        if (srp->cmd.cdb[0] == INQUIRY) {

            vscsi_inquiry_no_target(s, req);

        } else {

            vscsi_makeup_sense(s, req, ILLEGAL_REQUEST, 0x24, 0x00);

            vscsi_send_rsp(s, req, CHECK_CONDITION, 0, 0);

        } return 1;

    }



    req->sdev = sdev;

    req->lun = lun;

    n = sdev->info->send_command(sdev, req->qtag, srp->cmd.cdb, lun);



    dprintf("VSCSI: Queued command tag 0x%x CMD 0x%x ID %d LUN %d ret: %d\n",

            req->qtag, srp->cmd.cdb[0], id, lun, n);



    if (n) {

        





        req->writing = (n < 1);



        

        vscsi_preprocess_desc(req);

    }



    

    if (n > 0) {

        req->data_len = n;

        sdev->info->read_data(sdev, req->qtag);

    } else if (n < 0) {

        req->data_len = -n;

        sdev->info->write_data(sdev, req->qtag);

    }

    



    return 0;

}

        sdev->info->write_data(sdev, req->qtag);         sdev->info->read_data(sdev, req->qtag);     n = sdev->info->send_command(sdev, req->qtag, srp->cmd.cdb, lun);         sdev->info->read_data(sdev, req->qtag);         sdev->info->write_data(sdev, req->qtag);
static int FUNC_0(VSCSIState *VAR_0, vscsi_req *VAR_1)

{

    union srp_iu *VAR_2 = &VAR_1->iu.VAR_2;

    SCSIDevice *sdev;

    int VAR_3, VAR_4, VAR_5;



    vscsi_decode_id_lun(be64_to_cpu(VAR_2->cmd.VAR_5), &VAR_4, &VAR_5);



    

    sdev = (VAR_4 < 8 && VAR_5 < 16) ? VAR_0->bus.devs[VAR_4] : NULL;

    if (!sdev) {

        dprintf("VSCSI: Command for VAR_4 %d with no drive\VAR_3", VAR_4);

        if (VAR_2->cmd.cdb[0] == INQUIRY) {

            vscsi_inquiry_no_target(VAR_0, VAR_1);

        } else {

            vscsi_makeup_sense(VAR_0, VAR_1, ILLEGAL_REQUEST, 0x24, 0x00);

            vscsi_send_rsp(VAR_0, VAR_1, CHECK_CONDITION, 0, 0);

        } return 1;

    }



    VAR_1->sdev = sdev;

    VAR_1->VAR_5 = VAR_5;

    VAR_3 = sdev->info->send_command(sdev, VAR_1->qtag, VAR_2->cmd.cdb, VAR_5);



    dprintf("VSCSI: Queued command tag 0x%x CMD 0x%x ID %d LUN %d ret: %d\VAR_3",

            VAR_1->qtag, VAR_2->cmd.cdb[0], VAR_4, VAR_5, VAR_3);



    if (VAR_3) {

        





        VAR_1->writing = (VAR_3 < 1);



        

        vscsi_preprocess_desc(VAR_1);

    }



    

    if (VAR_3 > 0) {

        VAR_1->data_len = VAR_3;

        sdev->info->read_data(sdev, VAR_1->qtag);

    } else if (VAR_3 < 0) {

        VAR_1->data_len = -VAR_3;

        sdev->info->write_data(sdev, VAR_1->qtag);

    }

    



    return 0;

}

static int FUNC_0(VSCSIState *VAR_0, vscsi_req *VAR_1)
{ union srp_iu *VAR_2 = &VAR_1->iu.VAR_2; SCSIDevice *sdev; int VAR_3, VAR_4, VAR_5; vscsi_decode_id_lun(be64_to_cpu(VAR_2->cmd.VAR_5), &VAR_4, &VAR_5); sdev = (VAR_4 < 8 && VAR_5 < 16) ? VAR_0->bus.devs[VAR_4] : NULL; if (!sdev) { dprintf("VSCSI: Command for VAR_4 %d with no drive\VAR_3", VAR_4); if (VAR_2->cmd.cdb[0] == INQUIRY) { vscsi_inquiry_no_target(VAR_0, VAR_1); } else { vscsi_makeup_sense(VAR_0, VAR_1, ILLEGAL_REQUEST, 0x24, 0x00); vscsi_send_rsp(VAR_0, VAR_1, CHECK_CONDITION, 0, 0); } return 1; } VAR_1->sdev = sdev; VAR_1->VAR_5 = VAR_5; VAR_3 = sdev->info->send_command(sdev, VAR_1->qtag, VAR_2->cmd.cdb, VAR_5); dprintf("VSCSI: Queued command tag 0x%x CMD 0x%x ID %d LUN %d ret: %d\VAR_3",
VAR_1->qtag, VAR_2->cmd.cdb[0], VAR_4, VAR_5, VAR_3); if (VAR_3) { VAR_1->writing = (VAR_3 < 1); vscsi_preprocess_desc(VAR_1); } if (VAR_3 > 0) { VAR_1->data_len = VAR_3; sdev->info->read_data(sdev, VAR_1->qtag); } else if (VAR_3 < 0) { VAR_1->data_len = -VAR_3; sdev->info->write_data(sdev, VAR_1->qtag); } return 0; }