Revision 1cc91b7d hw/virtio-blk.c
b/hw/virtio-blk.c | ||
---|---|---|
23 | 23 |
#endif |
24 | 24 |
#include "hw/virtio-bus.h" |
25 | 25 |
|
26 |
/* |
|
27 |
* Moving to QOM later in this series. |
|
28 |
*/ |
|
29 |
static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev) |
|
30 |
{ |
|
31 |
return (VirtIOBlock *)vdev; |
|
32 |
} |
|
33 |
|
|
34 | 26 |
typedef struct VirtIOBlockReq |
35 | 27 |
{ |
36 | 28 |
VirtIOBlock *dev; |
... | ... | |
46 | 38 |
static void virtio_blk_req_complete(VirtIOBlockReq *req, int status) |
47 | 39 |
{ |
48 | 40 |
VirtIOBlock *s = req->dev; |
41 |
VirtIODevice *vdev = VIRTIO_DEVICE(s); |
|
49 | 42 |
|
50 | 43 |
trace_virtio_blk_req_complete(req, status); |
51 | 44 |
|
52 | 45 |
stb_p(&req->in->status, status); |
53 | 46 |
virtqueue_push(s->vq, &req->elem, req->qiov.size + sizeof(*req->in)); |
54 |
virtio_notify(&s->vdev, s->vq);
|
|
47 |
virtio_notify(vdev, s->vq); |
|
55 | 48 |
} |
56 | 49 |
|
57 | 50 |
static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, |
... | ... | |
396 | 389 |
|
397 | 390 |
static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) |
398 | 391 |
{ |
399 |
VirtIOBlock *s = to_virtio_blk(vdev);
|
|
392 |
VirtIOBlock *s = VIRTIO_BLK(vdev);
|
|
400 | 393 |
VirtIOBlockReq *req; |
401 | 394 |
MultiReqBuffer mrb = { |
402 | 395 |
.num_writes = 0, |
... | ... | |
464 | 457 |
static void virtio_blk_reset(VirtIODevice *vdev) |
465 | 458 |
{ |
466 | 459 |
#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE |
467 |
VirtIOBlock *s = to_virtio_blk(vdev);
|
|
460 |
VirtIOBlock *s = VIRTIO_BLK(vdev);
|
|
468 | 461 |
|
469 | 462 |
if (s->dataplane) { |
470 | 463 |
virtio_blk_data_plane_stop(s->dataplane); |
... | ... | |
482 | 475 |
*/ |
483 | 476 |
static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) |
484 | 477 |
{ |
485 |
VirtIOBlock *s = to_virtio_blk(vdev);
|
|
478 |
VirtIOBlock *s = VIRTIO_BLK(vdev);
|
|
486 | 479 |
struct virtio_blk_config blkcfg; |
487 | 480 |
uint64_t capacity; |
488 | 481 |
int blk_size = s->conf->logical_block_size; |
... | ... | |
521 | 514 |
|
522 | 515 |
static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config) |
523 | 516 |
{ |
524 |
VirtIOBlock *s = to_virtio_blk(vdev);
|
|
517 |
VirtIOBlock *s = VIRTIO_BLK(vdev);
|
|
525 | 518 |
struct virtio_blk_config blkcfg; |
526 | 519 |
|
527 | 520 |
memcpy(&blkcfg, config, sizeof(blkcfg)); |
... | ... | |
530 | 523 |
|
531 | 524 |
static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features) |
532 | 525 |
{ |
533 |
VirtIOBlock *s = to_virtio_blk(vdev);
|
|
526 |
VirtIOBlock *s = VIRTIO_BLK(vdev);
|
|
534 | 527 |
|
535 | 528 |
features |= (1 << VIRTIO_BLK_F_SEG_MAX); |
536 | 529 |
features |= (1 << VIRTIO_BLK_F_GEOMETRY); |
... | ... | |
552 | 545 |
|
553 | 546 |
static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status) |
554 | 547 |
{ |
555 |
VirtIOBlock *s = to_virtio_blk(vdev);
|
|
548 |
VirtIOBlock *s = VIRTIO_BLK(vdev);
|
|
556 | 549 |
uint32_t features; |
557 | 550 |
|
558 | 551 |
#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE |
... | ... | |
573 | 566 |
static void virtio_blk_save(QEMUFile *f, void *opaque) |
574 | 567 |
{ |
575 | 568 |
VirtIOBlock *s = opaque; |
569 |
VirtIODevice *vdev = VIRTIO_DEVICE(s); |
|
576 | 570 |
VirtIOBlockReq *req = s->rq; |
577 | 571 |
|
578 |
virtio_save(&s->vdev, f);
|
|
572 |
virtio_save(vdev, f); |
|
579 | 573 |
|
580 | 574 |
while (req) { |
581 | 575 |
qemu_put_sbyte(f, 1); |
... | ... | |
588 | 582 |
static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id) |
589 | 583 |
{ |
590 | 584 |
VirtIOBlock *s = opaque; |
585 |
VirtIODevice *vdev = VIRTIO_DEVICE(s); |
|
591 | 586 |
int ret; |
592 | 587 |
|
593 | 588 |
if (version_id != 2) |
594 | 589 |
return -EINVAL; |
595 | 590 |
|
596 |
ret = virtio_load(&s->vdev, f);
|
|
591 |
ret = virtio_load(vdev, f); |
|
597 | 592 |
if (ret) { |
598 | 593 |
return ret; |
599 | 594 |
} |
... | ... | |
615 | 610 |
|
616 | 611 |
static void virtio_blk_resize(void *opaque) |
617 | 612 |
{ |
618 |
VirtIOBlock *s = opaque;
|
|
613 |
VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
|
|
619 | 614 |
|
620 |
virtio_notify_config(&s->vdev);
|
|
615 |
virtio_notify_config(vdev); |
|
621 | 616 |
} |
622 | 617 |
|
623 | 618 |
static const BlockDevOps virtio_block_ops = { |
Also available in: Unified diff