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->lun = lun;

    req->sreq = scsi_req_new(sdev, req->qtag, lun, req);

    n = scsi_req_enqueue(req->sreq, srp->cmd.cdb);



    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;

        } else if (n < 0) {

            req->data_len = -n;

        }

        scsi_req_continue(req->sreq);

    }

    /* 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->lun = lun;

    req->sreq = scsi_req_new(sdev, req->qtag, lun, req);

    n = scsi_req_enqueue(req->sreq, srp->cmd.cdb);



    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;

        } else if (n < 0) {

            req->data_len = -n;

        }

        scsi_req_continue(req->sreq);

    }

    



    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->VAR_5 = VAR_5;

    VAR_1->sreq = scsi_req_new(sdev, VAR_1->qtag, VAR_5, VAR_1);

    VAR_3 = scsi_req_enqueue(VAR_1->sreq, VAR_2->cmd.cdb);



    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;

        } else if (VAR_3 < 0) {

            VAR_1->data_len = -VAR_3;

        }

        scsi_req_continue(VAR_1->sreq);

    }

    



    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->VAR_5 = VAR_5; VAR_1->sreq = scsi_req_new(sdev, VAR_1->qtag, VAR_5, VAR_1); VAR_3 = scsi_req_enqueue(VAR_1->sreq, VAR_2->cmd.cdb); 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; } else if (VAR_3 < 0) { VAR_1->data_len = -VAR_3; } scsi_req_continue(VAR_1->sreq); } return 0; }