parallel: QOM'ify
[qemu/agraf.git] / hw / block / virtio-blk.c
blobcf12469b50dcc5e897ae3c339dace2ba4f36dde7
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/block.h"
18 #include "sysemu/blockdev.h"
19 #include "hw/virtio/virtio-blk.h"
20 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
21 # include "dataplane/virtio-blk.h"
22 #endif
23 #include "block/scsi.h"
24 #ifdef __linux__
25 # include <scsi/sg.h>
26 #endif
27 #include "hw/virtio/virtio-bus.h"
29 typedef struct VirtIOBlockReq
31 VirtIOBlock *dev;
32 VirtQueueElement elem;
33 struct virtio_blk_inhdr *in;
34 struct virtio_blk_outhdr *out;
35 struct virtio_scsi_inhdr *scsi;
36 QEMUIOVector qiov;
37 struct VirtIOBlockReq *next;
38 BlockAcctCookie acct;
39 } VirtIOBlockReq;
41 static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
43 VirtIOBlock *s = req->dev;
44 VirtIODevice *vdev = VIRTIO_DEVICE(s);
46 trace_virtio_blk_req_complete(req, status);
48 stb_p(&req->in->status, status);
49 virtqueue_push(s->vq, &req->elem, req->qiov.size + sizeof(*req->in));
50 virtio_notify(vdev, s->vq);
53 static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
54 bool is_read)
56 BlockErrorAction action = bdrv_get_error_action(req->dev->bs, is_read, error);
57 VirtIOBlock *s = req->dev;
59 if (action == BDRV_ACTION_STOP) {
60 req->next = s->rq;
61 s->rq = req;
62 } else if (action == BDRV_ACTION_REPORT) {
63 virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
64 bdrv_acct_done(s->bs, &req->acct);
65 g_free(req);
68 bdrv_error_action(s->bs, action, is_read, error);
69 return action != BDRV_ACTION_IGNORE;
72 static void virtio_blk_rw_complete(void *opaque, int ret)
74 VirtIOBlockReq *req = opaque;
76 trace_virtio_blk_rw_complete(req, ret);
78 if (ret) {
79 bool is_read = !(ldl_p(&req->out->type) & VIRTIO_BLK_T_OUT);
80 if (virtio_blk_handle_rw_error(req, -ret, is_read))
81 return;
84 virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
85 bdrv_acct_done(req->dev->bs, &req->acct);
86 g_free(req);
89 static void virtio_blk_flush_complete(void *opaque, int ret)
91 VirtIOBlockReq *req = opaque;
93 if (ret) {
94 if (virtio_blk_handle_rw_error(req, -ret, 0)) {
95 return;
99 virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
100 bdrv_acct_done(req->dev->bs, &req->acct);
101 g_free(req);
104 static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
106 VirtIOBlockReq *req = g_malloc(sizeof(*req));
107 req->dev = s;
108 req->qiov.size = 0;
109 req->next = NULL;
110 return req;
113 static VirtIOBlockReq *virtio_blk_get_request(VirtIOBlock *s)
115 VirtIOBlockReq *req = virtio_blk_alloc_request(s);
117 if (req != NULL) {
118 if (!virtqueue_pop(s->vq, &req->elem)) {
119 g_free(req);
120 return NULL;
124 return req;
127 static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
129 #ifdef __linux__
130 int ret;
131 int i;
132 #endif
133 int status = VIRTIO_BLK_S_OK;
136 * We require at least one output segment each for the virtio_blk_outhdr
137 * and the SCSI command block.
139 * We also at least require the virtio_blk_inhdr, the virtio_scsi_inhdr
140 * and the sense buffer pointer in the input segments.
142 if (req->elem.out_num < 2 || req->elem.in_num < 3) {
143 virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
144 g_free(req);
145 return;
149 * The scsi inhdr is placed in the second-to-last input segment, just
150 * before the regular inhdr.
152 req->scsi = (void *)req->elem.in_sg[req->elem.in_num - 2].iov_base;
154 if (!req->dev->blk.scsi) {
155 status = VIRTIO_BLK_S_UNSUPP;
156 goto fail;
160 * No support for bidirection commands yet.
162 if (req->elem.out_num > 2 && req->elem.in_num > 3) {
163 status = VIRTIO_BLK_S_UNSUPP;
164 goto fail;
167 #ifdef __linux__
168 struct sg_io_hdr hdr;
169 memset(&hdr, 0, sizeof(struct sg_io_hdr));
170 hdr.interface_id = 'S';
171 hdr.cmd_len = req->elem.out_sg[1].iov_len;
172 hdr.cmdp = req->elem.out_sg[1].iov_base;
173 hdr.dxfer_len = 0;
175 if (req->elem.out_num > 2) {
177 * If there are more than the minimally required 2 output segments
178 * there is write payload starting from the third iovec.
180 hdr.dxfer_direction = SG_DXFER_TO_DEV;
181 hdr.iovec_count = req->elem.out_num - 2;
183 for (i = 0; i < hdr.iovec_count; i++)
184 hdr.dxfer_len += req->elem.out_sg[i + 2].iov_len;
186 hdr.dxferp = req->elem.out_sg + 2;
188 } else if (req->elem.in_num > 3) {
190 * If we have more than 3 input segments the guest wants to actually
191 * read data.
193 hdr.dxfer_direction = SG_DXFER_FROM_DEV;
194 hdr.iovec_count = req->elem.in_num - 3;
195 for (i = 0; i < hdr.iovec_count; i++)
196 hdr.dxfer_len += req->elem.in_sg[i].iov_len;
198 hdr.dxferp = req->elem.in_sg;
199 } else {
201 * Some SCSI commands don't actually transfer any data.
203 hdr.dxfer_direction = SG_DXFER_NONE;
206 hdr.sbp = req->elem.in_sg[req->elem.in_num - 3].iov_base;
207 hdr.mx_sb_len = req->elem.in_sg[req->elem.in_num - 3].iov_len;
209 ret = bdrv_ioctl(req->dev->bs, SG_IO, &hdr);
210 if (ret) {
211 status = VIRTIO_BLK_S_UNSUPP;
212 goto fail;
216 * From SCSI-Generic-HOWTO: "Some lower level drivers (e.g. ide-scsi)
217 * clear the masked_status field [hence status gets cleared too, see
218 * block/scsi_ioctl.c] even when a CHECK_CONDITION or COMMAND_TERMINATED
219 * status has occurred. However they do set DRIVER_SENSE in driver_status
220 * field. Also a (sb_len_wr > 0) indicates there is a sense buffer.
222 if (hdr.status == 0 && hdr.sb_len_wr > 0) {
223 hdr.status = CHECK_CONDITION;
226 stl_p(&req->scsi->errors,
227 hdr.status | (hdr.msg_status << 8) |
228 (hdr.host_status << 16) | (hdr.driver_status << 24));
229 stl_p(&req->scsi->residual, hdr.resid);
230 stl_p(&req->scsi->sense_len, hdr.sb_len_wr);
231 stl_p(&req->scsi->data_len, hdr.dxfer_len);
233 virtio_blk_req_complete(req, status);
234 g_free(req);
235 return;
236 #else
237 abort();
238 #endif
240 fail:
241 /* Just put anything nonzero so that the ioctl fails in the guest. */
242 stl_p(&req->scsi->errors, 255);
243 virtio_blk_req_complete(req, status);
244 g_free(req);
247 typedef struct MultiReqBuffer {
248 BlockRequest blkreq[32];
249 unsigned int num_writes;
250 } MultiReqBuffer;
252 static void virtio_submit_multiwrite(BlockDriverState *bs, MultiReqBuffer *mrb)
254 int i, ret;
256 if (!mrb->num_writes) {
257 return;
260 ret = bdrv_aio_multiwrite(bs, mrb->blkreq, mrb->num_writes);
261 if (ret != 0) {
262 for (i = 0; i < mrb->num_writes; i++) {
263 if (mrb->blkreq[i].error) {
264 virtio_blk_rw_complete(mrb->blkreq[i].opaque, -EIO);
269 mrb->num_writes = 0;
272 static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb)
274 bdrv_acct_start(req->dev->bs, &req->acct, 0, BDRV_ACCT_FLUSH);
277 * Make sure all outstanding writes are posted to the backing device.
279 virtio_submit_multiwrite(req->dev->bs, mrb);
280 bdrv_aio_flush(req->dev->bs, virtio_blk_flush_complete, req);
283 static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb)
285 BlockRequest *blkreq;
286 uint64_t sector;
288 sector = ldq_p(&req->out->sector);
290 bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_WRITE);
292 trace_virtio_blk_handle_write(req, sector, req->qiov.size / 512);
294 if (sector & req->dev->sector_mask) {
295 virtio_blk_rw_complete(req, -EIO);
296 return;
298 if (req->qiov.size % req->dev->conf->logical_block_size) {
299 virtio_blk_rw_complete(req, -EIO);
300 return;
303 if (mrb->num_writes == 32) {
304 virtio_submit_multiwrite(req->dev->bs, mrb);
307 blkreq = &mrb->blkreq[mrb->num_writes];
308 blkreq->sector = sector;
309 blkreq->nb_sectors = req->qiov.size / BDRV_SECTOR_SIZE;
310 blkreq->qiov = &req->qiov;
311 blkreq->cb = virtio_blk_rw_complete;
312 blkreq->opaque = req;
313 blkreq->error = 0;
315 mrb->num_writes++;
318 static void virtio_blk_handle_read(VirtIOBlockReq *req)
320 uint64_t sector;
322 sector = ldq_p(&req->out->sector);
324 bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_READ);
326 trace_virtio_blk_handle_read(req, sector, req->qiov.size / 512);
328 if (sector & req->dev->sector_mask) {
329 virtio_blk_rw_complete(req, -EIO);
330 return;
332 if (req->qiov.size % req->dev->conf->logical_block_size) {
333 virtio_blk_rw_complete(req, -EIO);
334 return;
336 bdrv_aio_readv(req->dev->bs, sector, &req->qiov,
337 req->qiov.size / BDRV_SECTOR_SIZE,
338 virtio_blk_rw_complete, req);
341 static void virtio_blk_handle_request(VirtIOBlockReq *req,
342 MultiReqBuffer *mrb)
344 uint32_t type;
346 if (req->elem.out_num < 1 || req->elem.in_num < 1) {
347 error_report("virtio-blk missing headers");
348 exit(1);
351 if (req->elem.out_sg[0].iov_len < sizeof(*req->out) ||
352 req->elem.in_sg[req->elem.in_num - 1].iov_len < sizeof(*req->in)) {
353 error_report("virtio-blk header not in correct element");
354 exit(1);
357 req->out = (void *)req->elem.out_sg[0].iov_base;
358 req->in = (void *)req->elem.in_sg[req->elem.in_num - 1].iov_base;
360 type = ldl_p(&req->out->type);
362 if (type & VIRTIO_BLK_T_FLUSH) {
363 virtio_blk_handle_flush(req, mrb);
364 } else if (type & VIRTIO_BLK_T_SCSI_CMD) {
365 virtio_blk_handle_scsi(req);
366 } else if (type & VIRTIO_BLK_T_GET_ID) {
367 VirtIOBlock *s = req->dev;
370 * NB: per existing s/n string convention the string is
371 * terminated by '\0' only when shorter than buffer.
373 strncpy(req->elem.in_sg[0].iov_base,
374 s->blk.serial ? s->blk.serial : "",
375 MIN(req->elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
376 virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
377 g_free(req);
378 } else if (type & VIRTIO_BLK_T_OUT) {
379 qemu_iovec_init_external(&req->qiov, &req->elem.out_sg[1],
380 req->elem.out_num - 1);
381 virtio_blk_handle_write(req, mrb);
382 } else if (type == VIRTIO_BLK_T_IN || type == VIRTIO_BLK_T_BARRIER) {
383 /* VIRTIO_BLK_T_IN is 0, so we can't just & it. */
384 qemu_iovec_init_external(&req->qiov, &req->elem.in_sg[0],
385 req->elem.in_num - 1);
386 virtio_blk_handle_read(req);
387 } else {
388 virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP);
389 g_free(req);
393 static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
395 VirtIOBlock *s = VIRTIO_BLK(vdev);
396 VirtIOBlockReq *req;
397 MultiReqBuffer mrb = {
398 .num_writes = 0,
401 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
402 /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start
403 * dataplane here instead of waiting for .set_status().
405 if (s->dataplane) {
406 virtio_blk_data_plane_start(s->dataplane);
407 return;
409 #endif
411 while ((req = virtio_blk_get_request(s))) {
412 virtio_blk_handle_request(req, &mrb);
415 virtio_submit_multiwrite(s->bs, &mrb);
418 * FIXME: Want to check for completions before returning to guest mode,
419 * so cached reads and writes are reported as quickly as possible. But
420 * that should be done in the generic block layer.
424 static void virtio_blk_dma_restart_bh(void *opaque)
426 VirtIOBlock *s = opaque;
427 VirtIOBlockReq *req = s->rq;
428 MultiReqBuffer mrb = {
429 .num_writes = 0,
432 qemu_bh_delete(s->bh);
433 s->bh = NULL;
435 s->rq = NULL;
437 while (req) {
438 virtio_blk_handle_request(req, &mrb);
439 req = req->next;
442 virtio_submit_multiwrite(s->bs, &mrb);
445 static void virtio_blk_dma_restart_cb(void *opaque, int running,
446 RunState state)
448 VirtIOBlock *s = opaque;
450 if (!running) {
451 return;
454 if (!s->bh) {
455 s->bh = qemu_bh_new(virtio_blk_dma_restart_bh, s);
456 qemu_bh_schedule(s->bh);
460 static void virtio_blk_reset(VirtIODevice *vdev)
462 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
463 VirtIOBlock *s = VIRTIO_BLK(vdev);
465 if (s->dataplane) {
466 virtio_blk_data_plane_stop(s->dataplane);
468 #endif
471 * This should cancel pending requests, but can't do nicely until there
472 * are per-device request lists.
474 bdrv_drain_all();
477 /* coalesce internal state, copy to pci i/o region 0
479 static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
481 VirtIOBlock *s = VIRTIO_BLK(vdev);
482 struct virtio_blk_config blkcfg;
483 uint64_t capacity;
484 int blk_size = s->conf->logical_block_size;
486 bdrv_get_geometry(s->bs, &capacity);
487 memset(&blkcfg, 0, sizeof(blkcfg));
488 stq_raw(&blkcfg.capacity, capacity);
489 stl_raw(&blkcfg.seg_max, 128 - 2);
490 stw_raw(&blkcfg.cylinders, s->conf->cyls);
491 stl_raw(&blkcfg.blk_size, blk_size);
492 stw_raw(&blkcfg.min_io_size, s->conf->min_io_size / blk_size);
493 stw_raw(&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
494 blkcfg.heads = s->conf->heads;
496 * We must ensure that the block device capacity is a multiple of
497 * the logical block size. If that is not the case, let's use
498 * sector_mask to adopt the geometry to have a correct picture.
499 * For those devices where the capacity is ok for the given geometry
500 * we don't touch the sector value of the geometry, since some devices
501 * (like s390 dasd) need a specific value. Here the capacity is already
502 * cyls*heads*secs*blk_size and the sector value is not block size
503 * divided by 512 - instead it is the amount of blk_size blocks
504 * per track (cylinder).
506 if (bdrv_getlength(s->bs) / s->conf->heads / s->conf->secs % blk_size) {
507 blkcfg.sectors = s->conf->secs & ~s->sector_mask;
508 } else {
509 blkcfg.sectors = s->conf->secs;
511 blkcfg.size_max = 0;
512 blkcfg.physical_block_exp = get_physical_block_exp(s->conf);
513 blkcfg.alignment_offset = 0;
514 blkcfg.wce = bdrv_enable_write_cache(s->bs);
515 memcpy(config, &blkcfg, sizeof(struct virtio_blk_config));
518 static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
520 VirtIOBlock *s = VIRTIO_BLK(vdev);
521 struct virtio_blk_config blkcfg;
523 memcpy(&blkcfg, config, sizeof(blkcfg));
524 bdrv_set_enable_write_cache(s->bs, blkcfg.wce != 0);
527 static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
529 VirtIOBlock *s = VIRTIO_BLK(vdev);
531 features |= (1 << VIRTIO_BLK_F_SEG_MAX);
532 features |= (1 << VIRTIO_BLK_F_GEOMETRY);
533 features |= (1 << VIRTIO_BLK_F_TOPOLOGY);
534 features |= (1 << VIRTIO_BLK_F_BLK_SIZE);
535 features |= (1 << VIRTIO_BLK_F_SCSI);
537 if (s->blk.config_wce) {
538 features |= (1 << VIRTIO_BLK_F_CONFIG_WCE);
540 if (bdrv_enable_write_cache(s->bs))
541 features |= (1 << VIRTIO_BLK_F_WCE);
543 if (bdrv_is_read_only(s->bs))
544 features |= 1 << VIRTIO_BLK_F_RO;
546 return features;
549 static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
551 VirtIOBlock *s = VIRTIO_BLK(vdev);
552 uint32_t features;
554 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
555 if (s->dataplane && !(status & (VIRTIO_CONFIG_S_DRIVER |
556 VIRTIO_CONFIG_S_DRIVER_OK))) {
557 virtio_blk_data_plane_stop(s->dataplane);
559 #endif
561 if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
562 return;
565 features = vdev->guest_features;
566 bdrv_set_enable_write_cache(s->bs, !!(features & (1 << VIRTIO_BLK_F_WCE)));
569 static void virtio_blk_save(QEMUFile *f, void *opaque)
571 VirtIOBlock *s = opaque;
572 VirtIODevice *vdev = VIRTIO_DEVICE(s);
573 VirtIOBlockReq *req = s->rq;
575 virtio_save(vdev, f);
577 while (req) {
578 qemu_put_sbyte(f, 1);
579 qemu_put_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
580 req = req->next;
582 qemu_put_sbyte(f, 0);
585 static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
587 VirtIOBlock *s = opaque;
588 VirtIODevice *vdev = VIRTIO_DEVICE(s);
589 int ret;
591 if (version_id != 2)
592 return -EINVAL;
594 ret = virtio_load(vdev, f);
595 if (ret) {
596 return ret;
599 while (qemu_get_sbyte(f)) {
600 VirtIOBlockReq *req = virtio_blk_alloc_request(s);
601 qemu_get_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
602 req->next = s->rq;
603 s->rq = req;
605 virtqueue_map_sg(req->elem.in_sg, req->elem.in_addr,
606 req->elem.in_num, 1);
607 virtqueue_map_sg(req->elem.out_sg, req->elem.out_addr,
608 req->elem.out_num, 0);
611 return 0;
614 static void virtio_blk_resize(void *opaque)
616 VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
618 virtio_notify_config(vdev);
621 static const BlockDevOps virtio_block_ops = {
622 .resize_cb = virtio_blk_resize,
625 void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk)
627 VirtIOBlock *s = VIRTIO_BLK(dev);
628 memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
631 static int virtio_blk_device_init(VirtIODevice *vdev)
633 DeviceState *qdev = DEVICE(vdev);
634 VirtIOBlock *s = VIRTIO_BLK(vdev);
635 VirtIOBlkConf *blk = &(s->blk);
636 static int virtio_blk_id;
638 if (!blk->conf.bs) {
639 error_report("drive property not set");
640 return -1;
642 if (!bdrv_is_inserted(blk->conf.bs)) {
643 error_report("Device needs media, but drive is empty");
644 return -1;
647 blkconf_serial(&blk->conf, &blk->serial);
648 if (blkconf_geometry(&blk->conf, NULL, 65535, 255, 255) < 0) {
649 return -1;
652 virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
653 sizeof(struct virtio_blk_config));
655 s->bs = blk->conf.bs;
656 s->conf = &blk->conf;
657 memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
658 s->rq = NULL;
659 s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
661 s->vq = virtio_add_queue(vdev, 128, virtio_blk_handle_output);
662 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
663 if (!virtio_blk_data_plane_create(vdev, blk, &s->dataplane)) {
664 virtio_cleanup(vdev);
665 return -1;
667 #endif
669 s->change = qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
670 register_savevm(qdev, "virtio-blk", virtio_blk_id++, 2,
671 virtio_blk_save, virtio_blk_load, s);
672 bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
673 bdrv_set_buffer_alignment(s->bs, s->conf->logical_block_size);
675 bdrv_iostatus_enable(s->bs);
677 add_boot_device_path(s->conf->bootindex, qdev, "/disk@0,0");
678 return 0;
681 static int virtio_blk_device_exit(DeviceState *dev)
683 VirtIODevice *vdev = VIRTIO_DEVICE(dev);
684 VirtIOBlock *s = VIRTIO_BLK(dev);
685 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
686 virtio_blk_data_plane_destroy(s->dataplane);
687 s->dataplane = NULL;
688 #endif
689 qemu_del_vm_change_state_handler(s->change);
690 unregister_savevm(dev, "virtio-blk", s);
691 blockdev_mark_auto_del(s->bs);
692 virtio_cleanup(vdev);
693 return 0;
696 static Property virtio_blk_properties[] = {
697 DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlock, blk),
698 DEFINE_PROP_END_OF_LIST(),
701 static void virtio_blk_class_init(ObjectClass *klass, void *data)
703 DeviceClass *dc = DEVICE_CLASS(klass);
704 VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
705 dc->exit = virtio_blk_device_exit;
706 dc->props = virtio_blk_properties;
707 vdc->init = virtio_blk_device_init;
708 vdc->get_config = virtio_blk_update_config;
709 vdc->set_config = virtio_blk_set_config;
710 vdc->get_features = virtio_blk_get_features;
711 vdc->set_status = virtio_blk_set_status;
712 vdc->reset = virtio_blk_reset;
715 static const TypeInfo virtio_device_info = {
716 .name = TYPE_VIRTIO_BLK,
717 .parent = TYPE_VIRTIO_DEVICE,
718 .instance_size = sizeof(VirtIOBlock),
719 .class_init = virtio_blk_class_init,
722 static void virtio_register_types(void)
724 type_register_static(&virtio_device_info);
727 type_init(virtio_register_types)