Revision afa46c46

b/hw/scsi-bus.c
7 7
#include "trace.h"
8 8

  
9 9
static char *scsibus_get_fw_dev_path(DeviceState *dev);
10
static int scsi_req_parse(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf);
10 11
static int scsi_build_sense(uint8_t *in_buf, int in_len,
11 12
                            uint8_t *buf, int len, bool fixed);
12 13

  
......
134 135
    return res;
135 136
}
136 137

  
138
/* SCSIReqOps implementation for invalid commands.  */
139

  
140
static int32_t scsi_invalid_command(SCSIRequest *req, uint8_t *buf)
141
{
142
    scsi_req_build_sense(req, SENSE_CODE(INVALID_OPCODE));
143
    scsi_req_complete(req, CHECK_CONDITION);
144
    return 0;
145
}
146

  
147
struct SCSIReqOps reqops_invalid_opcode = {
148
    .size         = sizeof(SCSIRequest),
149
    .send_command = scsi_invalid_command
150
};
151

  
137 152
SCSIRequest *scsi_req_alloc(SCSIReqOps *reqops, SCSIDevice *d, uint32_t tag,
138 153
                            uint32_t lun, void *hba_private)
139 154
{
......
157 172
                          uint8_t *buf, void *hba_private)
158 173
{
159 174
    SCSIRequest *req;
160
    req = d->info->alloc_req(d, tag, lun, hba_private);
161
    memcpy(req->cmd.buf, buf, 16);
175
    SCSICommand cmd;
176

  
177
    if (scsi_req_parse(&cmd, d, buf) != 0) {
178
        trace_scsi_req_parse_bad(d->id, lun, tag, buf[0]);
179
        req = scsi_req_alloc(&reqops_invalid_opcode, d, tag, lun, hba_private);
180
    } else {
181
        trace_scsi_req_parsed(d->id, lun, tag, buf[0],
182
                              cmd.mode, cmd.xfer);
183
        if (req->cmd.lba != -1) {
184
            trace_scsi_req_parsed_lba(d->id, lun, tag, buf[0],
185
                                      cmd.lba);
186
        }
187
        req = d->info->alloc_req(d, tag, lun, hba_private);
188
    }
189

  
190
    req->cmd = cmd;
162 191
    return req;
163 192
}
164 193

  
......
424 453
    return lba;
425 454
}
426 455

  
427
int scsi_req_parse(SCSIRequest *req, uint8_t *buf)
456
int scsi_req_parse(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
428 457
{
429 458
    int rc;
430 459

  
431
    if (req->dev->type == TYPE_TAPE) {
432
        rc = scsi_req_stream_length(&req->cmd, req->dev, buf);
460
    if (dev->type == TYPE_TAPE) {
461
        rc = scsi_req_stream_length(cmd, dev, buf);
433 462
    } else {
434
        rc = scsi_req_length(&req->cmd, req->dev, buf);
463
        rc = scsi_req_length(cmd, dev, buf);
435 464
    }
436 465
    if (rc != 0)
437 466
        return rc;
438 467

  
439
    assert(buf == req->cmd.buf);
440
    scsi_cmd_xfer_mode(&req->cmd);
441
    req->cmd.lba = scsi_cmd_lba(&req->cmd);
442
    trace_scsi_req_parsed(req->dev->id, req->lun, req->tag, buf[0],
443
                          req->cmd.mode, req->cmd.xfer);
444
    if (req->cmd.lba != -1) {
445
        trace_scsi_req_parsed_lba(req->dev->id, req->lun, req->tag, buf[0],
446
                              req->cmd.lba);
447
    }
468
    memcpy(cmd->buf, buf, cmd->len);
469
    scsi_cmd_xfer_mode(cmd);
470
    cmd->lba = scsi_cmd_lba(cmd);
448 471
    return 0;
449 472
}
450 473

  
b/hw/scsi-disk.c
964 964
    outbuf = (uint8_t *)r->iov.iov_base;
965 965
    DPRINTF("Command: lun=%d tag=0x%x data=0x%02x", req->lun, req->tag, buf[0]);
966 966

  
967
    if (scsi_req_parse(&r->req, buf) != 0) {
968
        BADF("Unsupported command length, command %x\n", command);
969
        scsi_check_condition(r, SENSE_CODE(INVALID_OPCODE));
970
        return 0;
971
    }
972 967
#ifdef DEBUG_SCSI
973 968
    {
974 969
        int i;
b/hw/scsi-generic.c
84 84
        case -EDOM:
85 85
            status = TASK_SET_FULL;
86 86
            break;
87
        case -EINVAL:
88
            status = CHECK_CONDITION;
89
            scsi_req_build_sense(&r->req, SENSE_CODE(INVALID_FIELD));
90
            break;
91 87
        case -ENOMEM:
92 88
            status = CHECK_CONDITION;
93 89
            scsi_req_build_sense(&r->req, SENSE_CODE(TARGET_FAILURE));
......
298 294
        return 0;
299 295
    }
300 296

  
301
    if (-1 == scsi_req_parse(&r->req, cmd)) {
302
        BADF("Unsupported command length, command %x\n", cmd[0]);
303
        scsi_command_complete(r, -EINVAL);
304
        return 0;
305
    }
306 297
    scsi_req_fixup(&r->req);
307 298

  
308 299
    DPRINTF("Command: lun=%d tag=0x%x len %zd data=0x%02x", lun, tag,
b/hw/scsi.h
165 165
void scsi_req_unref(SCSIRequest *req);
166 166

  
167 167
void scsi_req_build_sense(SCSIRequest *req, SCSISense sense);
168
int scsi_req_parse(SCSIRequest *req, uint8_t *buf);
169 168
void scsi_req_print(SCSIRequest *req);
170 169
void scsi_req_continue(SCSIRequest *req);
171 170
void scsi_req_data(SCSIRequest *req, int len);

Also available in: Unified diff