~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to hw/scsi/scsi-bus.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
static char *scsibus_get_fw_dev_path(DeviceState *dev);
12
12
static int scsi_req_parse(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf);
13
13
static void scsi_req_dequeue(SCSIRequest *req);
 
14
static uint8_t *scsi_target_alloc_buf(SCSIRequest *req, size_t len);
 
15
static void scsi_target_free_buf(SCSIRequest *req);
14
16
 
15
17
static Property scsi_props[] = {
16
18
    DEFINE_PROP_UINT32("channel", SCSIDevice, channel, 0),
209
211
/* handle legacy '-drive if=scsi,...' cmd line args */
210
212
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
211
213
                                      int unit, bool removable, int bootindex,
212
 
                                      const char *serial)
 
214
                                      const char *serial, Error **errp)
213
215
{
214
216
    const char *driver;
215
217
    DeviceState *dev;
 
218
    Error *err = NULL;
216
219
 
217
220
    driver = bdrv_is_sg(bdrv) ? "scsi-generic" : "scsi-disk";
218
221
    dev = qdev_create(&bus->qbus, driver);
223
226
    if (object_property_find(OBJECT(dev), "removable", NULL)) {
224
227
        qdev_prop_set_bit(dev, "removable", removable);
225
228
    }
226
 
    if (serial) {
 
229
    if (serial && object_property_find(OBJECT(dev), "serial", NULL)) {
227
230
        qdev_prop_set_string(dev, "serial", serial);
228
231
    }
229
232
    if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
230
 
        qdev_free(dev);
231
 
        return NULL;
232
 
    }
233
 
    if (qdev_init(dev) < 0)
234
 
        return NULL;
 
233
        error_setg(errp, "Setting drive property failed");
 
234
        qdev_free(dev);
 
235
        return NULL;
 
236
    }
 
237
    object_property_set_bool(OBJECT(dev), true, "realized", &err);
 
238
    if (err != NULL) {
 
239
        error_propagate(errp, err);
 
240
        qdev_free(dev);
 
241
        return NULL;
 
242
    }
235
243
    return SCSI_DEVICE(dev);
236
244
}
237
245
 
238
 
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
 
246
void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, Error **errp)
239
247
{
240
248
    Location loc;
241
249
    DriveInfo *dinfo;
242
 
    int res = 0, unit;
 
250
    int unit;
 
251
    Error *err = NULL;
243
252
 
244
253
    loc_push_none(&loc);
245
254
    for (unit = 0; unit <= bus->info->max_target; unit++) {
248
257
            continue;
249
258
        }
250
259
        qemu_opts_loc_restore(dinfo->opts);
251
 
        if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1, NULL)) {
252
 
            res = -1;
 
260
        scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1, NULL,
 
261
                                  &err);
 
262
        if (err != NULL) {
 
263
            error_propagate(errp, err);
253
264
            break;
254
265
        }
255
266
    }
256
267
    loc_pop(&loc);
257
 
    return res;
258
268
}
259
269
 
260
270
static int32_t scsi_invalid_field(SCSIRequest *req, uint8_t *buf)
309
319
struct SCSITargetReq {
310
320
    SCSIRequest req;
311
321
    int len;
312
 
    uint8_t buf[2056];
 
322
    uint8_t *buf;
 
323
    int buf_len;
313
324
};
314
325
 
315
326
static void store_lun(uint8_t *outbuf, int lun)
353
364
    if (!found_lun0) {
354
365
        n += 8;
355
366
    }
 
367
 
 
368
    scsi_target_alloc_buf(&r->req, n + 8);
 
369
 
356
370
    len = MIN(n + 8, r->req.cmd.xfer & ~7);
357
 
    if (len > sizeof(r->buf)) {
358
 
        /* TODO: > 256 LUNs? */
359
 
        return false;
360
 
    }
361
 
 
362
371
    memset(r->buf, 0, len);
363
 
    stl_be_p(&r->buf, n);
 
372
    stl_be_p(r->buf, n);
364
373
    i = found_lun0 ? 8 : 16;
365
374
    QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) {
366
375
        DeviceState *qdev = kid->child;
379
388
static bool scsi_target_emulate_inquiry(SCSITargetReq *r)
380
389
{
381
390
    assert(r->req.dev->lun != r->req.lun);
 
391
 
 
392
    scsi_target_alloc_buf(&r->req, SCSI_INQUIRY_LEN);
 
393
 
382
394
    if (r->req.cmd.buf[1] & 0x2) {
383
395
        /* Command support data - optional, not implemented */
384
396
        return false;
403
415
            return false;
404
416
        }
405
417
        /* done with EVPD */
406
 
        assert(r->len < sizeof(r->buf));
 
418
        assert(r->len < r->buf_len);
407
419
        r->len = MIN(r->req.cmd.xfer, r->len);
408
420
        return true;
409
421
    }
447
459
        }
448
460
        break;
449
461
    case REQUEST_SENSE:
450
 
        r->len = scsi_device_get_sense(r->req.dev, r->buf,
451
 
                                       MIN(req->cmd.xfer, sizeof r->buf),
 
462
        scsi_target_alloc_buf(&r->req, SCSI_SENSE_LEN);
 
463
        r->len = scsi_device_get_sense(r->req.dev, r->buf, r->buf_len,
452
464
                                       (req->cmd.buf[1] & 1) == 0);
453
465
        if (r->req.dev->sense_is_ua) {
454
466
            scsi_device_unit_attention_reported(req->dev);
493
505
    return r->buf;
494
506
}
495
507
 
 
508
static uint8_t *scsi_target_alloc_buf(SCSIRequest *req, size_t len)
 
509
{
 
510
    SCSITargetReq *r = DO_UPCAST(SCSITargetReq, req, req);
 
511
 
 
512
    r->buf = g_malloc(len);
 
513
    r->buf_len = len;
 
514
 
 
515
    return r->buf;
 
516
}
 
517
 
 
518
static void scsi_target_free_buf(SCSIRequest *req)
 
519
{
 
520
    SCSITargetReq *r = DO_UPCAST(SCSITargetReq, req, req);
 
521
 
 
522
    g_free(r->buf);
 
523
}
 
524
 
496
525
static const struct SCSIReqOps reqops_target_command = {
497
526
    .size         = sizeof(SCSITargetReq),
498
527
    .send_command = scsi_target_send_command,
499
528
    .read_data    = scsi_target_read_data,
500
529
    .get_buf      = scsi_target_get_buf,
 
530
    .free_req     = scsi_target_free_buf,
501
531
};
502
532
 
503
533
 
505
535
                            uint32_t tag, uint32_t lun, void *hba_private)
506
536
{
507
537
    SCSIRequest *req;
 
538
    SCSIBus *bus = scsi_bus_from_device(d);
 
539
    BusState *qbus = BUS(bus);
508
540
 
509
541
    req = g_malloc0(reqops->size);
510
542
    req->refcount = 1;
511
 
    req->bus = scsi_bus_from_device(d);
 
543
    req->bus = bus;
512
544
    req->dev = d;
513
545
    req->tag = tag;
514
546
    req->lun = lun;
516
548
    req->status = -1;
517
549
    req->sense_len = 0;
518
550
    req->ops = reqops;
 
551
    object_ref(OBJECT(d));
 
552
    object_ref(OBJECT(qbus->parent));
519
553
    trace_scsi_req_alloc(req->dev->id, req->lun, req->tag);
520
554
    return req;
521
555
}
1353
1387
        buf[7] = 10;
1354
1388
        buf[12] = sense.asc;
1355
1389
        buf[13] = sense.ascq;
1356
 
        return MIN(len, 18);
 
1390
        return MIN(len, SCSI_SENSE_LEN);
1357
1391
    } else {
1358
1392
        /* Return descriptor format sense buffer */
1359
1393
        buf[0] = 0x72;
1498
1532
{
1499
1533
    assert(req->refcount > 0);
1500
1534
    if (--req->refcount == 0) {
1501
 
        SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, req->dev->qdev.parent_bus);
 
1535
        BusState *qbus = req->dev->qdev.parent_bus;
 
1536
        SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, qbus);
 
1537
 
1502
1538
        if (bus->info->free_request && req->hba_private) {
1503
1539
            bus->info->free_request(bus, req->hba_private);
1504
1540
        }
1505
1541
        if (req->ops->free_req) {
1506
1542
            req->ops->free_req(req);
1507
1543
        }
 
1544
        object_unref(OBJECT(req->dev));
 
1545
        object_unref(OBJECT(qbus->parent));
1508
1546
        g_free(req);
1509
1547
    }
1510
1548
}
1865
1903
static void scsi_device_class_init(ObjectClass *klass, void *data)
1866
1904
{
1867
1905
    DeviceClass *k = DEVICE_CLASS(klass);
 
1906
    set_bit(DEVICE_CATEGORY_STORAGE, k->categories);
1868
1907
    k->bus_type = TYPE_SCSI_BUS;
1869
1908
    k->init     = scsi_qdev_init;
1870
1909
    k->unplug   = scsi_qdev_unplug;