acpi_table_add(): extract and reimplement internals
[qemu/ar7.git] / hw / virtio-blk.c
blobf2143fded389a902ddb07510b2c3cbd2589c8d16
1 /*
2 * Virtio Block Device
4 * Copyright IBM, Corp. 2007
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #include "qemu-common.h"
15 #include "qemu/error-report.h"
16 #include "trace.h"
17 #include "hw/block-common.h"
18 #include "sysemu/blockdev.h"
19 #include "hw/virtio-blk.h"
20 #include "hw/scsi-defs.h"
21 #ifdef __linux__
22 # include <scsi/sg.h>
23 #endif
24 #include "hw/virtio-bus.h"
26 typedef struct VirtIOBlockReq
28 VirtIOBlock *dev;
29 VirtQueueElement elem;
30 struct virtio_blk_inhdr *in;
31 struct virtio_blk_outhdr *out;
32 struct virtio_scsi_inhdr *scsi;
33 QEMUIOVector qiov;
34 struct VirtIOBlockReq *next;
35 BlockAcctCookie acct;
36 } VirtIOBlockReq;
38 static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
40 VirtIOBlock *s = req->dev;
41 VirtIODevice *vdev = VIRTIO_DEVICE(s);
43 trace_virtio_blk_req_complete(req, status);
45 stb_p(&req->in->status, status);
46 virtqueue_push(s->vq, &req->elem, req->qiov.size + sizeof(*req->in));
47 virtio_notify(vdev, s->vq);
50 static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
51 bool is_read)
53 BlockErrorAction action = bdrv_get_error_action(req->dev->bs, is_read, error);
54 VirtIOBlock *s = req->dev;
56 if (action == BDRV_ACTION_STOP) {
57 req->next = s->rq;
58 s->rq = req;
59 } else if (action == BDRV_ACTION_REPORT) {
60 virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
61 bdrv_acct_done(s->bs, &req->acct);
62 g_free(req);
65 bdrv_error_action(s->bs, action, is_read, error);
66 return action != BDRV_ACTION_IGNORE;
69 static void virtio_blk_rw_complete(void *opaque, int ret)
71 VirtIOBlockReq *req = opaque;
73 trace_virtio_blk_rw_complete(req, ret);
75 if (ret) {
76 bool is_read = !(ldl_p(&req->out->type) & VIRTIO_BLK_T_OUT);
77 if (virtio_blk_handle_rw_error(req, -ret, is_read))
78 return;
81 virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
82 bdrv_acct_done(req->dev->bs, &req->acct);
83 g_free(req);
86 static void virtio_blk_flush_complete(void *opaque, int ret)
88 VirtIOBlockReq *req = opaque;
90 if (ret) {
91 if (virtio_blk_handle_rw_error(req, -ret, 0)) {
92 return;
96 virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
97 bdrv_acct_done(req->dev->bs, &req->acct);
98 g_free(req);
101 static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
103 VirtIOBlockReq *req = g_malloc(sizeof(*req));
104 req->dev = s;
105 req->qiov.size = 0;
106 req->next = NULL;
107 return req;
110 static VirtIOBlockReq *virtio_blk_get_request(VirtIOBlock *s)
112 VirtIOBlockReq *req = virtio_blk_alloc_request(s);
114 if (req != NULL) {
115 if (!virtqueue_pop(s->vq, &req->elem)) {
116 g_free(req);
117 return NULL;
121 return req;
124 static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
126 #ifdef __linux__
127 int ret;
128 int i;
129 #endif
130 int status = VIRTIO_BLK_S_OK;
133 * We require at least one output segment each for the virtio_blk_outhdr
134 * and the SCSI command block.
136 * We also at least require the virtio_blk_inhdr, the virtio_scsi_inhdr
137 * and the sense buffer pointer in the input segments.
139 if (req->elem.out_num < 2 || req->elem.in_num < 3) {
140 virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
141 g_free(req);
142 return;
146 * The scsi inhdr is placed in the second-to-last input segment, just
147 * before the regular inhdr.
149 req->scsi = (void *)req->elem.in_sg[req->elem.in_num - 2].iov_base;
151 if (!req->dev->blk.scsi) {
152 status = VIRTIO_BLK_S_UNSUPP;
153 goto fail;
157 * No support for bidirection commands yet.
159 if (req->elem.out_num > 2 && req->elem.in_num > 3) {
160 status = VIRTIO_BLK_S_UNSUPP;
161 goto fail;
164 #ifdef __linux__
165 struct sg_io_hdr hdr;
166 memset(&hdr, 0, sizeof(struct sg_io_hdr));
167 hdr.interface_id = 'S';
168 hdr.cmd_len = req->elem.out_sg[1].iov_len;
169 hdr.cmdp = req->elem.out_sg[1].iov_base;
170 hdr.dxfer_len = 0;
172 if (req->elem.out_num > 2) {
174 * If there are more than the minimally required 2 output segments
175 * there is write payload starting from the third iovec.
177 hdr.dxfer_direction = SG_DXFER_TO_DEV;
178 hdr.iovec_count = req->elem.out_num - 2;
180 for (i = 0; i < hdr.iovec_count; i++)
181 hdr.dxfer_len += req->elem.out_sg[i + 2].iov_len;
183 hdr.dxferp = req->elem.out_sg + 2;
185 } else if (req->elem.in_num > 3) {
187 * If we have more than 3 input segments the guest wants to actually
188 * read data.
190 hdr.dxfer_direction = SG_DXFER_FROM_DEV;
191 hdr.iovec_count = req->elem.in_num - 3;
192 for (i = 0; i < hdr.iovec_count; i++)
193 hdr.dxfer_len += req->elem.in_sg[i].iov_len;
195 hdr.dxferp = req->elem.in_sg;
196 } else {
198 * Some SCSI commands don't actually transfer any data.
200 hdr.dxfer_direction = SG_DXFER_NONE;
203 hdr.sbp = req->elem.in_sg[req->elem.in_num - 3].iov_base;
204 hdr.mx_sb_len = req->elem.in_sg[req->elem.in_num - 3].iov_len;
206 ret = bdrv_ioctl(req->dev->bs, SG_IO, &hdr);
207 if (ret) {
208 status = VIRTIO_BLK_S_UNSUPP;
209 goto fail;
213 * From SCSI-Generic-HOWTO: "Some lower level drivers (e.g. ide-scsi)
214 * clear the masked_status field [hence status gets cleared too, see
215 * block/scsi_ioctl.c] even when a CHECK_CONDITION or COMMAND_TERMINATED
216 * status has occurred. However they do set DRIVER_SENSE in driver_status
217 * field. Also a (sb_len_wr > 0) indicates there is a sense buffer.
219 if (hdr.status == 0 && hdr.sb_len_wr > 0) {
220 hdr.status = CHECK_CONDITION;
223 stl_p(&req->scsi->errors,
224 hdr.status | (hdr.msg_status << 8) |
225 (hdr.host_status << 16) | (hdr.driver_status << 24));
226 stl_p(&req->scsi->residual, hdr.resid);
227 stl_p(&req->scsi->sense_len, hdr.sb_len_wr);
228 stl_p(&req->scsi->data_len, hdr.dxfer_len);
230 virtio_blk_req_complete(req, status);
231 g_free(req);
232 return;
233 #else
234 abort();
235 #endif
237 fail:
238 /* Just put anything nonzero so that the ioctl fails in the guest. */
239 stl_p(&req->scsi->errors, 255);
240 virtio_blk_req_complete(req, status);
241 g_free(req);
244 typedef struct MultiReqBuffer {
245 BlockRequest blkreq[32];
246 unsigned int num_writes;
247 } MultiReqBuffer;
249 static void virtio_submit_multiwrite(BlockDriverState *bs, MultiReqBuffer *mrb)
251 int i, ret;
253 if (!mrb->num_writes) {
254 return;
257 ret = bdrv_aio_multiwrite(bs, mrb->blkreq, mrb->num_writes);
258 if (ret != 0) {
259 for (i = 0; i < mrb->num_writes; i++) {
260 if (mrb->blkreq[i].error) {
261 virtio_blk_rw_complete(mrb->blkreq[i].opaque, -EIO);
266 mrb->num_writes = 0;
269 static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb)
271 bdrv_acct_start(req->dev->bs, &req->acct, 0, BDRV_ACCT_FLUSH);
274 * Make sure all outstanding writes are posted to the backing device.
276 virtio_submit_multiwrite(req->dev->bs, mrb);
277 bdrv_aio_flush(req->dev->bs, virtio_blk_flush_complete, req);
280 static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb)
282 BlockRequest *blkreq;
283 uint64_t sector;
285 sector = ldq_p(&req->out->sector);
287 bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_WRITE);
289 trace_virtio_blk_handle_write(req, sector, req->qiov.size / 512);
291 if (sector & req->dev->sector_mask) {
292 virtio_blk_rw_complete(req, -EIO);
293 return;
295 if (req->qiov.size % req->dev->conf->logical_block_size) {
296 virtio_blk_rw_complete(req, -EIO);
297 return;
300 if (mrb->num_writes == 32) {
301 virtio_submit_multiwrite(req->dev->bs, mrb);
304 blkreq = &mrb->blkreq[mrb->num_writes];
305 blkreq->sector = sector;
306 blkreq->nb_sectors = req->qiov.size / BDRV_SECTOR_SIZE;
307 blkreq->qiov = &req->qiov;
308 blkreq->cb = virtio_blk_rw_complete;
309 blkreq->opaque = req;
310 blkreq->error = 0;
312 mrb->num_writes++;
315 static void virtio_blk_handle_read(VirtIOBlockReq *req)
317 uint64_t sector;
319 sector = ldq_p(&req->out->sector);
321 bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_READ);
323 trace_virtio_blk_handle_read(req, sector, req->qiov.size / 512);
325 if (sector & req->dev->sector_mask) {
326 virtio_blk_rw_complete(req, -EIO);
327 return;
329 if (req->qiov.size % req->dev->conf->logical_block_size) {
330 virtio_blk_rw_complete(req, -EIO);
331 return;
333 bdrv_aio_readv(req->dev->bs, sector, &req->qiov,
334 req->qiov.size / BDRV_SECTOR_SIZE,
335 virtio_blk_rw_complete, req);
338 static void virtio_blk_handle_request(VirtIOBlockReq *req,
339 MultiReqBuffer *mrb)
341 uint32_t type;
343 if (req->elem.out_num < 1 || req->elem.in_num < 1) {
344 error_report("virtio-blk missing headers");
345 exit(1);
348 if (req->elem.out_sg[0].iov_len < sizeof(*req->out) ||
349 req->elem.in_sg[req->elem.in_num - 1].iov_len < sizeof(*req->in)) {
350 error_report("virtio-blk header not in correct element");
351 exit(1);
354 req->out = (void *)req->elem.out_sg[0].iov_base;
355 req->in = (void *)req->elem.in_sg[req->elem.in_num - 1].iov_base;
357 type = ldl_p(&req->out->type);
359 if (type & VIRTIO_BLK_T_FLUSH) {
360 virtio_blk_handle_flush(req, mrb);
361 } else if (type & VIRTIO_BLK_T_SCSI_CMD) {
362 virtio_blk_handle_scsi(req);
363 } else if (type & VIRTIO_BLK_T_GET_ID) {
364 VirtIOBlock *s = req->dev;
367 * NB: per existing s/n string convention the string is
368 * terminated by '\0' only when shorter than buffer.
370 strncpy(req->elem.in_sg[0].iov_base,
371 s->blk.serial ? s->blk.serial : "",
372 MIN(req->elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
373 virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
374 g_free(req);
375 } else if (type & VIRTIO_BLK_T_OUT) {
376 qemu_iovec_init_external(&req->qiov, &req->elem.out_sg[1],
377 req->elem.out_num - 1);
378 virtio_blk_handle_write(req, mrb);
379 } else if (type == VIRTIO_BLK_T_IN || type == VIRTIO_BLK_T_BARRIER) {
380 /* VIRTIO_BLK_T_IN is 0, so we can't just & it. */
381 qemu_iovec_init_external(&req->qiov, &req->elem.in_sg[0],
382 req->elem.in_num - 1);
383 virtio_blk_handle_read(req);
384 } else {
385 virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP);
386 g_free(req);
390 static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
392 VirtIOBlock *s = VIRTIO_BLK(vdev);
393 VirtIOBlockReq *req;
394 MultiReqBuffer mrb = {
395 .num_writes = 0,
398 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
399 /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start
400 * dataplane here instead of waiting for .set_status().
402 if (s->dataplane) {
403 virtio_blk_data_plane_start(s->dataplane);
404 return;
406 #endif
408 while ((req = virtio_blk_get_request(s))) {
409 virtio_blk_handle_request(req, &mrb);
412 virtio_submit_multiwrite(s->bs, &mrb);
415 * FIXME: Want to check for completions before returning to guest mode,
416 * so cached reads and writes are reported as quickly as possible. But
417 * that should be done in the generic block layer.
421 static void virtio_blk_dma_restart_bh(void *opaque)
423 VirtIOBlock *s = opaque;
424 VirtIOBlockReq *req = s->rq;
425 MultiReqBuffer mrb = {
426 .num_writes = 0,
429 qemu_bh_delete(s->bh);
430 s->bh = NULL;
432 s->rq = NULL;
434 while (req) {
435 virtio_blk_handle_request(req, &mrb);
436 req = req->next;
439 virtio_submit_multiwrite(s->bs, &mrb);
442 static void virtio_blk_dma_restart_cb(void *opaque, int running,
443 RunState state)
445 VirtIOBlock *s = opaque;
447 if (!running) {
448 return;
451 if (!s->bh) {
452 s->bh = qemu_bh_new(virtio_blk_dma_restart_bh, s);
453 qemu_bh_schedule(s->bh);
457 static void virtio_blk_reset(VirtIODevice *vdev)
459 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
460 VirtIOBlock *s = VIRTIO_BLK(vdev);
462 if (s->dataplane) {
463 virtio_blk_data_plane_stop(s->dataplane);
465 #endif
468 * This should cancel pending requests, but can't do nicely until there
469 * are per-device request lists.
471 bdrv_drain_all();
474 /* coalesce internal state, copy to pci i/o region 0
476 static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
478 VirtIOBlock *s = VIRTIO_BLK(vdev);
479 struct virtio_blk_config blkcfg;
480 uint64_t capacity;
481 int blk_size = s->conf->logical_block_size;
483 bdrv_get_geometry(s->bs, &capacity);
484 memset(&blkcfg, 0, sizeof(blkcfg));
485 stq_raw(&blkcfg.capacity, capacity);
486 stl_raw(&blkcfg.seg_max, 128 - 2);
487 stw_raw(&blkcfg.cylinders, s->conf->cyls);
488 stl_raw(&blkcfg.blk_size, blk_size);
489 stw_raw(&blkcfg.min_io_size, s->conf->min_io_size / blk_size);
490 stw_raw(&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
491 blkcfg.heads = s->conf->heads;
493 * We must ensure that the block device capacity is a multiple of
494 * the logical block size. If that is not the case, lets use
495 * sector_mask to adopt the geometry to have a correct picture.
496 * For those devices where the capacity is ok for the given geometry
497 * we dont touch the sector value of the geometry, since some devices
498 * (like s390 dasd) need a specific value. Here the capacity is already
499 * cyls*heads*secs*blk_size and the sector value is not block size
500 * divided by 512 - instead it is the amount of blk_size blocks
501 * per track (cylinder).
503 if (bdrv_getlength(s->bs) / s->conf->heads / s->conf->secs % blk_size) {
504 blkcfg.sectors = s->conf->secs & ~s->sector_mask;
505 } else {
506 blkcfg.sectors = s->conf->secs;
508 blkcfg.size_max = 0;
509 blkcfg.physical_block_exp = get_physical_block_exp(s->conf);
510 blkcfg.alignment_offset = 0;
511 blkcfg.wce = bdrv_enable_write_cache(s->bs);
512 memcpy(config, &blkcfg, sizeof(struct virtio_blk_config));
515 static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
517 VirtIOBlock *s = VIRTIO_BLK(vdev);
518 struct virtio_blk_config blkcfg;
520 memcpy(&blkcfg, config, sizeof(blkcfg));
521 bdrv_set_enable_write_cache(s->bs, blkcfg.wce != 0);
524 static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
526 VirtIOBlock *s = VIRTIO_BLK(vdev);
528 features |= (1 << VIRTIO_BLK_F_SEG_MAX);
529 features |= (1 << VIRTIO_BLK_F_GEOMETRY);
530 features |= (1 << VIRTIO_BLK_F_TOPOLOGY);
531 features |= (1 << VIRTIO_BLK_F_BLK_SIZE);
532 features |= (1 << VIRTIO_BLK_F_SCSI);
534 if (s->blk.config_wce) {
535 features |= (1 << VIRTIO_BLK_F_CONFIG_WCE);
537 if (bdrv_enable_write_cache(s->bs))
538 features |= (1 << VIRTIO_BLK_F_WCE);
540 if (bdrv_is_read_only(s->bs))
541 features |= 1 << VIRTIO_BLK_F_RO;
543 return features;
546 static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
548 VirtIOBlock *s = VIRTIO_BLK(vdev);
549 uint32_t features;
551 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
552 if (s->dataplane && !(status & (VIRTIO_CONFIG_S_DRIVER |
553 VIRTIO_CONFIG_S_DRIVER_OK))) {
554 virtio_blk_data_plane_stop(s->dataplane);
556 #endif
558 if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
559 return;
562 features = vdev->guest_features;
563 bdrv_set_enable_write_cache(s->bs, !!(features & (1 << VIRTIO_BLK_F_WCE)));
566 static void virtio_blk_save(QEMUFile *f, void *opaque)
568 VirtIOBlock *s = opaque;
569 VirtIODevice *vdev = VIRTIO_DEVICE(s);
570 VirtIOBlockReq *req = s->rq;
572 virtio_save(vdev, f);
574 while (req) {
575 qemu_put_sbyte(f, 1);
576 qemu_put_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
577 req = req->next;
579 qemu_put_sbyte(f, 0);
582 static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
584 VirtIOBlock *s = opaque;
585 VirtIODevice *vdev = VIRTIO_DEVICE(s);
586 int ret;
588 if (version_id != 2)
589 return -EINVAL;
591 ret = virtio_load(vdev, f);
592 if (ret) {
593 return ret;
596 while (qemu_get_sbyte(f)) {
597 VirtIOBlockReq *req = virtio_blk_alloc_request(s);
598 qemu_get_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
599 req->next = s->rq;
600 s->rq = req;
602 virtqueue_map_sg(req->elem.in_sg, req->elem.in_addr,
603 req->elem.in_num, 1);
604 virtqueue_map_sg(req->elem.out_sg, req->elem.out_addr,
605 req->elem.out_num, 0);
608 return 0;
611 static void virtio_blk_resize(void *opaque)
613 VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
615 virtio_notify_config(vdev);
618 static const BlockDevOps virtio_block_ops = {
619 .resize_cb = virtio_blk_resize,
622 void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk)
624 VirtIOBlock *s = VIRTIO_BLK(dev);
625 memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
628 static int virtio_blk_device_init(VirtIODevice *vdev)
630 DeviceState *qdev = DEVICE(vdev);
631 VirtIOBlock *s = VIRTIO_BLK(vdev);
632 VirtIOBlkConf *blk = &(s->blk);
633 static int virtio_blk_id;
635 if (!blk->conf.bs) {
636 error_report("drive property not set");
637 return -1;
639 if (!bdrv_is_inserted(blk->conf.bs)) {
640 error_report("Device needs media, but drive is empty");
641 return -1;
644 blkconf_serial(&blk->conf, &blk->serial);
645 if (blkconf_geometry(&blk->conf, NULL, 65535, 255, 255) < 0) {
646 return -1;
649 virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
650 sizeof(struct virtio_blk_config));
652 vdev->get_config = virtio_blk_update_config;
653 vdev->set_config = virtio_blk_set_config;
654 vdev->get_features = virtio_blk_get_features;
655 vdev->set_status = virtio_blk_set_status;
656 vdev->reset = virtio_blk_reset;
657 s->bs = blk->conf.bs;
658 s->conf = &blk->conf;
659 memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
660 s->rq = NULL;
661 s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
663 s->vq = virtio_add_queue(vdev, 128, virtio_blk_handle_output);
664 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
665 if (!virtio_blk_data_plane_create(vdev, blk, &s->dataplane)) {
666 virtio_common_cleanup(vdev);
667 return -1;
669 #endif
671 s->change = qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
672 register_savevm(qdev, "virtio-blk", virtio_blk_id++, 2,
673 virtio_blk_save, virtio_blk_load, s);
674 bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
675 bdrv_set_buffer_alignment(s->bs, s->conf->logical_block_size);
677 bdrv_iostatus_enable(s->bs);
679 add_boot_device_path(s->conf->bootindex, qdev, "/disk@0,0");
680 return 0;
683 static int virtio_blk_device_exit(DeviceState *dev)
685 VirtIODevice *vdev = VIRTIO_DEVICE(dev);
686 VirtIOBlock *s = VIRTIO_BLK(dev);
687 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
688 virtio_blk_data_plane_destroy(s->dataplane);
689 s->dataplane = NULL;
690 #endif
691 qemu_del_vm_change_state_handler(s->change);
692 unregister_savevm(dev, "virtio-blk", s);
693 blockdev_mark_auto_del(s->bs);
694 virtio_common_cleanup(vdev);
695 return 0;
698 static Property virtio_blk_properties[] = {
699 DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlock, blk),
700 DEFINE_PROP_END_OF_LIST(),
703 static void virtio_blk_class_init(ObjectClass *klass, void *data)
705 DeviceClass *dc = DEVICE_CLASS(klass);
706 VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
707 dc->exit = virtio_blk_device_exit;
708 dc->props = virtio_blk_properties;
709 vdc->init = virtio_blk_device_init;
710 vdc->get_config = virtio_blk_update_config;
711 vdc->set_config = virtio_blk_set_config;
712 vdc->get_features = virtio_blk_get_features;
713 vdc->set_status = virtio_blk_set_status;
714 vdc->reset = virtio_blk_reset;
717 static const TypeInfo virtio_device_info = {
718 .name = TYPE_VIRTIO_BLK,
719 .parent = TYPE_VIRTIO_DEVICE,
720 .instance_size = sizeof(VirtIOBlock),
721 .class_init = virtio_blk_class_init,
724 static void virtio_register_types(void)
726 type_register_static(&virtio_device_info);
729 type_init(virtio_register_types)