]> git.proxmox.com Git - mirror_qemu.git/blame - hw/virtio-blk.c
block/raw-posix: Linux compat-ioctl warning workaround
[mirror_qemu.git] / hw / virtio-blk.c
CommitLineData
6e02c38d
AL
1/*
2 * Virtio Block Device
3 *
4 * Copyright IBM, Corp. 2007
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 */
13
869a5c6d 14#include <qemu-common.h>
d75d25e3 15#include "qemu-error.h"
6d519a5f 16#include "trace.h"
2446333c 17#include "blockdev.h"
6e02c38d 18#include "virtio-blk.h"
1063b8b1
CH
19#ifdef __linux__
20# include <scsi/sg.h>
21#endif
6e02c38d
AL
22
23typedef struct VirtIOBlock
24{
25 VirtIODevice vdev;
26 BlockDriverState *bs;
27 VirtQueue *vq;
869a5c6d 28 void *rq;
213189ab 29 QEMUBH *bh;
9752c371 30 BlockConf *conf;
8cfacf07 31 unsigned short sector_mask;
2930b313 32 char sn[BLOCK_SERIAL_STRLEN];
9d0d3138 33 DeviceState *qdev;
6e02c38d
AL
34} VirtIOBlock;
35
36static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
37{
38 return (VirtIOBlock *)vdev;
39}
40
41typedef struct VirtIOBlockReq
42{
43 VirtIOBlock *dev;
44 VirtQueueElement elem;
45 struct virtio_blk_inhdr *in;
46 struct virtio_blk_outhdr *out;
1063b8b1 47 struct virtio_scsi_inhdr *scsi;
d28a1b6e 48 QEMUIOVector qiov;
869a5c6d 49 struct VirtIOBlockReq *next;
6e02c38d
AL
50} VirtIOBlockReq;
51
869a5c6d
AL
52static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
53{
54 VirtIOBlock *s = req->dev;
55
6d519a5f
SH
56 trace_virtio_blk_req_complete(req, status);
57
92e3c2a3 58 stb_p(&req->in->status, status);
d28a1b6e 59 virtqueue_push(s->vq, &req->elem, req->qiov.size + sizeof(*req->in));
869a5c6d
AL
60 virtio_notify(&s->vdev, s->vq);
61
869a5c6d
AL
62 qemu_free(req);
63}
64
f35d68f0
KW
65static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
66 int is_read)
869a5c6d 67{
abd7f68d 68 BlockErrorAction action = bdrv_get_on_error(req->dev->bs, is_read);
869a5c6d
AL
69 VirtIOBlock *s = req->dev;
70
eaa6c85f 71 if (action == BLOCK_ERR_IGNORE) {
908bb949 72 bdrv_mon_event(s->bs, BDRV_ACTION_IGNORE, is_read);
869a5c6d 73 return 0;
eaa6c85f 74 }
869a5c6d
AL
75
76 if ((error == ENOSPC && action == BLOCK_ERR_STOP_ENOSPC)
77 || action == BLOCK_ERR_STOP_ANY) {
78 req->next = s->rq;
79 s->rq = req;
908bb949 80 bdrv_mon_event(s->bs, BDRV_ACTION_STOP, is_read);
e07bbac5 81 vm_stop(VMSTOP_DISKFULL);
869a5c6d
AL
82 } else {
83 virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
908bb949 84 bdrv_mon_event(s->bs, BDRV_ACTION_REPORT, is_read);
869a5c6d
AL
85 }
86
87 return 1;
88}
89
6e02c38d
AL
90static void virtio_blk_rw_complete(void *opaque, int ret)
91{
92 VirtIOBlockReq *req = opaque;
6e02c38d 93
6d519a5f
SH
94 trace_virtio_blk_rw_complete(req, ret);
95
f35d68f0 96 if (ret) {
92e3c2a3 97 int is_read = !(ldl_p(&req->out->type) & VIRTIO_BLK_T_OUT);
f35d68f0 98 if (virtio_blk_handle_rw_error(req, -ret, is_read))
869a5c6d 99 return;
6e02c38d
AL
100 }
101
f35d68f0 102 virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
869a5c6d 103}
6e02c38d 104
aa659be3
CH
105static void virtio_blk_flush_complete(void *opaque, int ret)
106{
107 VirtIOBlockReq *req = opaque;
108
8c269b54
KW
109 if (ret) {
110 if (virtio_blk_handle_rw_error(req, -ret, 0)) {
111 return;
112 }
113 }
114
115 virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
aa659be3
CH
116}
117
869a5c6d
AL
118static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
119{
de6c8042 120 VirtIOBlockReq *req = qemu_malloc(sizeof(*req));
487414f1 121 req->dev = s;
de6c8042
SH
122 req->qiov.size = 0;
123 req->next = NULL;
869a5c6d 124 return req;
6e02c38d
AL
125}
126
127static VirtIOBlockReq *virtio_blk_get_request(VirtIOBlock *s)
128{
869a5c6d 129 VirtIOBlockReq *req = virtio_blk_alloc_request(s);
6e02c38d 130
869a5c6d
AL
131 if (req != NULL) {
132 if (!virtqueue_pop(s->vq, &req->elem)) {
133 qemu_free(req);
134 return NULL;
135 }
6e02c38d
AL
136 }
137
138 return req;
139}
140
1063b8b1
CH
141#ifdef __linux__
142static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
143{
144 struct sg_io_hdr hdr;
4277906d 145 int ret;
1063b8b1
CH
146 int status;
147 int i;
148
149 /*
150 * We require at least one output segment each for the virtio_blk_outhdr
151 * and the SCSI command block.
152 *
153 * We also at least require the virtio_blk_inhdr, the virtio_scsi_inhdr
154 * and the sense buffer pointer in the input segments.
155 */
156 if (req->elem.out_num < 2 || req->elem.in_num < 3) {
157 virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
158 return;
159 }
160
161 /*
162 * No support for bidirection commands yet.
163 */
164 if (req->elem.out_num > 2 && req->elem.in_num > 3) {
165 virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP);
166 return;
167 }
168
169 /*
170 * The scsi inhdr is placed in the second-to-last input segment, just
171 * before the regular inhdr.
172 */
173 req->scsi = (void *)req->elem.in_sg[req->elem.in_num - 2].iov_base;
1063b8b1
CH
174
175 memset(&hdr, 0, sizeof(struct sg_io_hdr));
176 hdr.interface_id = 'S';
177 hdr.cmd_len = req->elem.out_sg[1].iov_len;
178 hdr.cmdp = req->elem.out_sg[1].iov_base;
179 hdr.dxfer_len = 0;
180
181 if (req->elem.out_num > 2) {
182 /*
183 * If there are more than the minimally required 2 output segments
184 * there is write payload starting from the third iovec.
185 */
186 hdr.dxfer_direction = SG_DXFER_TO_DEV;
187 hdr.iovec_count = req->elem.out_num - 2;
188
189 for (i = 0; i < hdr.iovec_count; i++)
190 hdr.dxfer_len += req->elem.out_sg[i + 2].iov_len;
191
192 hdr.dxferp = req->elem.out_sg + 2;
193
194 } else if (req->elem.in_num > 3) {
195 /*
196 * If we have more than 3 input segments the guest wants to actually
197 * read data.
198 */
199 hdr.dxfer_direction = SG_DXFER_FROM_DEV;
200 hdr.iovec_count = req->elem.in_num - 3;
201 for (i = 0; i < hdr.iovec_count; i++)
202 hdr.dxfer_len += req->elem.in_sg[i].iov_len;
203
204 hdr.dxferp = req->elem.in_sg;
1063b8b1
CH
205 } else {
206 /*
207 * Some SCSI commands don't actually transfer any data.
208 */
209 hdr.dxfer_direction = SG_DXFER_NONE;
210 }
211
212 hdr.sbp = req->elem.in_sg[req->elem.in_num - 3].iov_base;
213 hdr.mx_sb_len = req->elem.in_sg[req->elem.in_num - 3].iov_len;
1063b8b1
CH
214
215 ret = bdrv_ioctl(req->dev->bs, SG_IO, &hdr);
216 if (ret) {
217 status = VIRTIO_BLK_S_UNSUPP;
218 hdr.status = ret;
219 hdr.resid = hdr.dxfer_len;
220 } else if (hdr.status) {
221 status = VIRTIO_BLK_S_IOERR;
222 } else {
223 status = VIRTIO_BLK_S_OK;
224 }
225
92e3c2a3
AJ
226 stl_p(&req->scsi->errors, hdr.status);
227 stl_p(&req->scsi->residual, hdr.resid);
228 stl_p(&req->scsi->sense_len, hdr.sb_len_wr);
229 stl_p(&req->scsi->data_len, hdr.dxfer_len);
1063b8b1
CH
230
231 virtio_blk_req_complete(req, status);
232}
233#else
234static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
235{
236 virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP);
237}
238#endif /* __linux__ */
239
c20fd872
CH
240typedef struct MultiReqBuffer {
241 BlockRequest blkreq[32];
242 unsigned int num_writes;
243} MultiReqBuffer;
244
245static void virtio_submit_multiwrite(BlockDriverState *bs, MultiReqBuffer *mrb)
869a5c6d 246{
91553dcc 247 int i, ret;
91553dcc 248
c20fd872
CH
249 if (!mrb->num_writes) {
250 return;
251 }
252
253 ret = bdrv_aio_multiwrite(bs, mrb->blkreq, mrb->num_writes);
91553dcc 254 if (ret != 0) {
c20fd872
CH
255 for (i = 0; i < mrb->num_writes; i++) {
256 if (mrb->blkreq[i].error) {
257 virtio_blk_rw_complete(mrb->blkreq[i].opaque, -EIO);
91553dcc
KW
258 }
259 }
260 }
c20fd872
CH
261
262 mrb->num_writes = 0;
91553dcc 263}
87b245db 264
c20fd872 265static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb)
aa659be3
CH
266{
267 BlockDriverAIOCB *acb;
268
618fbb84
CH
269 /*
270 * Make sure all outstanding writes are posted to the backing device.
271 */
c20fd872 272 virtio_submit_multiwrite(req->dev->bs, mrb);
618fbb84 273
aa659be3
CH
274 acb = bdrv_aio_flush(req->dev->bs, virtio_blk_flush_complete, req);
275 if (!acb) {
18a8d421 276 virtio_blk_flush_complete(req, -EIO);
aa659be3
CH
277 }
278}
279
c20fd872 280static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb)
91553dcc 281{
c20fd872 282 BlockRequest *blkreq;
92e3c2a3 283 uint64_t sector;
c20fd872 284
92e3c2a3 285 sector = ldq_p(&req->out->sector);
6d519a5f 286
92e3c2a3
AJ
287 trace_virtio_blk_handle_write(req, sector, req->qiov.size / 512);
288
289 if (sector & req->dev->sector_mask) {
8cfacf07
CH
290 virtio_blk_rw_complete(req, -EIO);
291 return;
292 }
52c05023
CH
293 if (req->qiov.size % req->dev->conf->logical_block_size) {
294 virtio_blk_rw_complete(req, -EIO);
295 return;
296 }
8cfacf07 297
c20fd872
CH
298 if (mrb->num_writes == 32) {
299 virtio_submit_multiwrite(req->dev->bs, mrb);
87b245db 300 }
91553dcc 301
c20fd872 302 blkreq = &mrb->blkreq[mrb->num_writes];
92e3c2a3 303 blkreq->sector = sector;
c20fd872
CH
304 blkreq->nb_sectors = req->qiov.size / BDRV_SECTOR_SIZE;
305 blkreq->qiov = &req->qiov;
306 blkreq->cb = virtio_blk_rw_complete;
307 blkreq->opaque = req;
308 blkreq->error = 0;
91553dcc 309
c20fd872 310 mrb->num_writes++;
d28a1b6e 311}
869a5c6d 312
d28a1b6e
AL
313static void virtio_blk_handle_read(VirtIOBlockReq *req)
314{
87b245db 315 BlockDriverAIOCB *acb;
92e3c2a3
AJ
316 uint64_t sector;
317
318 sector = ldq_p(&req->out->sector);
87b245db 319
92e3c2a3 320 if (sector & req->dev->sector_mask) {
8cfacf07
CH
321 virtio_blk_rw_complete(req, -EIO);
322 return;
323 }
52c05023
CH
324 if (req->qiov.size % req->dev->conf->logical_block_size) {
325 virtio_blk_rw_complete(req, -EIO);
326 return;
327 }
8cfacf07 328
92e3c2a3 329 acb = bdrv_aio_readv(req->dev->bs, sector, &req->qiov,
1573a35d
JS
330 req->qiov.size / BDRV_SECTOR_SIZE,
331 virtio_blk_rw_complete, req);
87b245db 332 if (!acb) {
6c510fbf 333 virtio_blk_rw_complete(req, -EIO);
87b245db 334 }
869a5c6d
AL
335}
336
bc6694d4
KW
337static void virtio_blk_handle_request(VirtIOBlockReq *req,
338 MultiReqBuffer *mrb)
339{
92e3c2a3
AJ
340 uint32_t type;
341
bc6694d4 342 if (req->elem.out_num < 1 || req->elem.in_num < 1) {
870cef1d 343 error_report("virtio-blk missing headers");
bc6694d4
KW
344 exit(1);
345 }
346
347 if (req->elem.out_sg[0].iov_len < sizeof(*req->out) ||
348 req->elem.in_sg[req->elem.in_num - 1].iov_len < sizeof(*req->in)) {
870cef1d 349 error_report("virtio-blk header not in correct element");
bc6694d4
KW
350 exit(1);
351 }
352
353 req->out = (void *)req->elem.out_sg[0].iov_base;
354 req->in = (void *)req->elem.in_sg[req->elem.in_num - 1].iov_base;
355
92e3c2a3
AJ
356 type = ldl_p(&req->out->type);
357
358 if (type & VIRTIO_BLK_T_FLUSH) {
c20fd872 359 virtio_blk_handle_flush(req, mrb);
92e3c2a3 360 } else if (type & VIRTIO_BLK_T_SCSI_CMD) {
bc6694d4 361 virtio_blk_handle_scsi(req);
92e3c2a3 362 } else if (type & VIRTIO_BLK_T_GET_ID) {
2930b313 363 VirtIOBlock *s = req->dev;
364
365 memcpy(req->elem.in_sg[0].iov_base, s->sn,
366 MIN(req->elem.in_sg[0].iov_len, sizeof(s->sn)));
367 virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
92e3c2a3 368 } else if (type & VIRTIO_BLK_T_OUT) {
bc6694d4
KW
369 qemu_iovec_init_external(&req->qiov, &req->elem.out_sg[1],
370 req->elem.out_num - 1);
c20fd872 371 virtio_blk_handle_write(req, mrb);
bc6694d4
KW
372 } else {
373 qemu_iovec_init_external(&req->qiov, &req->elem.in_sg[0],
374 req->elem.in_num - 1);
375 virtio_blk_handle_read(req);
376 }
377}
378
6e02c38d
AL
379static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
380{
381 VirtIOBlock *s = to_virtio_blk(vdev);
382 VirtIOBlockReq *req;
bc6694d4
KW
383 MultiReqBuffer mrb = {
384 .num_writes = 0,
bc6694d4 385 };
6e02c38d
AL
386
387 while ((req = virtio_blk_get_request(s))) {
bc6694d4 388 virtio_blk_handle_request(req, &mrb);
6e02c38d 389 }
91553dcc 390
c20fd872 391 virtio_submit_multiwrite(s->bs, &mrb);
91553dcc 392
6e02c38d
AL
393 /*
394 * FIXME: Want to check for completions before returning to guest mode,
395 * so cached reads and writes are reported as quickly as possible. But
396 * that should be done in the generic block layer.
397 */
398}
399
213189ab 400static void virtio_blk_dma_restart_bh(void *opaque)
869a5c6d
AL
401{
402 VirtIOBlock *s = opaque;
403 VirtIOBlockReq *req = s->rq;
f1b52868
KW
404 MultiReqBuffer mrb = {
405 .num_writes = 0,
f1b52868 406 };
869a5c6d 407
213189ab
MA
408 qemu_bh_delete(s->bh);
409 s->bh = NULL;
869a5c6d
AL
410
411 s->rq = NULL;
412
413 while (req) {
f1b52868 414 virtio_blk_handle_request(req, &mrb);
869a5c6d
AL
415 req = req->next;
416 }
f1b52868 417
c20fd872 418 virtio_submit_multiwrite(s->bs, &mrb);
869a5c6d
AL
419}
420
213189ab
MA
421static void virtio_blk_dma_restart_cb(void *opaque, int running, int reason)
422{
423 VirtIOBlock *s = opaque;
424
425 if (!running)
426 return;
427
428 if (!s->bh) {
429 s->bh = qemu_bh_new(virtio_blk_dma_restart_bh, s);
430 qemu_bh_schedule(s->bh);
431 }
432}
433
6e02c38d
AL
434static void virtio_blk_reset(VirtIODevice *vdev)
435{
436 /*
437 * This should cancel pending requests, but can't do nicely until there
438 * are per-device request lists.
439 */
440 qemu_aio_flush();
441}
442
bf011293 443/* coalesce internal state, copy to pci i/o region 0
444 */
6e02c38d
AL
445static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
446{
447 VirtIOBlock *s = to_virtio_blk(vdev);
448 struct virtio_blk_config blkcfg;
449 uint64_t capacity;
450 int cylinders, heads, secs;
451
452 bdrv_get_geometry(s->bs, &capacity);
453 bdrv_get_geometry_hint(s->bs, &cylinders, &heads, &secs);
5c5dafdc 454 memset(&blkcfg, 0, sizeof(blkcfg));
6e02c38d
AL
455 stq_raw(&blkcfg.capacity, capacity);
456 stl_raw(&blkcfg.seg_max, 128 - 2);
457 stw_raw(&blkcfg.cylinders, cylinders);
458 blkcfg.heads = heads;
8cfacf07
CH
459 blkcfg.sectors = secs & ~s->sector_mask;
460 blkcfg.blk_size = s->conf->logical_block_size;
c7085da7 461 blkcfg.size_max = 0;
9752c371
CH
462 blkcfg.physical_block_exp = get_physical_block_exp(s->conf);
463 blkcfg.alignment_offset = 0;
8cfacf07
CH
464 blkcfg.min_io_size = s->conf->min_io_size / blkcfg.blk_size;
465 blkcfg.opt_io_size = s->conf->opt_io_size / blkcfg.blk_size;
37d5ddd6 466 memcpy(config, &blkcfg, sizeof(struct virtio_blk_config));
6e02c38d
AL
467}
468
8172539d 469static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
6e02c38d 470{
bf011293 471 VirtIOBlock *s = to_virtio_blk(vdev);
1063b8b1
CH
472
473 features |= (1 << VIRTIO_BLK_F_SEG_MAX);
474 features |= (1 << VIRTIO_BLK_F_GEOMETRY);
9752c371 475 features |= (1 << VIRTIO_BLK_F_TOPOLOGY);
8cfacf07 476 features |= (1 << VIRTIO_BLK_F_BLK_SIZE);
aa659be3
CH
477
478 if (bdrv_enable_write_cache(s->bs))
479 features |= (1 << VIRTIO_BLK_F_WCACHE);
c79662f7
NS
480
481 if (bdrv_is_read_only(s->bs))
482 features |= 1 << VIRTIO_BLK_F_RO;
1063b8b1
CH
483
484 return features;
6e02c38d
AL
485}
486
487static void virtio_blk_save(QEMUFile *f, void *opaque)
488{
489 VirtIOBlock *s = opaque;
869a5c6d
AL
490 VirtIOBlockReq *req = s->rq;
491
6e02c38d 492 virtio_save(&s->vdev, f);
869a5c6d
AL
493
494 while (req) {
495 qemu_put_sbyte(f, 1);
496 qemu_put_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
497 req = req->next;
498 }
499 qemu_put_sbyte(f, 0);
6e02c38d
AL
500}
501
502static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
503{
504 VirtIOBlock *s = opaque;
505
869a5c6d 506 if (version_id != 2)
6e02c38d
AL
507 return -EINVAL;
508
509 virtio_load(&s->vdev, f);
869a5c6d
AL
510 while (qemu_get_sbyte(f)) {
511 VirtIOBlockReq *req = virtio_blk_alloc_request(s);
512 qemu_get_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
513 req->next = s->rq;
20a81e4d 514 s->rq = req;
b6a4805b
KW
515
516 virtqueue_map_sg(req->elem.in_sg, req->elem.in_addr,
517 req->elem.in_num, 1);
518 virtqueue_map_sg(req->elem.out_sg, req->elem.out_addr,
519 req->elem.out_num, 0);
869a5c6d 520 }
6e02c38d
AL
521
522 return 0;
523}
524
e5051fc7
CH
525static void virtio_blk_change_cb(void *opaque, int reason)
526{
527 VirtIOBlock *s = opaque;
528
529 if (reason & CHANGE_SIZE) {
530 virtio_notify_config(&s->vdev);
531 }
532}
533
428c149b 534VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf)
6e02c38d
AL
535{
536 VirtIOBlock *s;
537 int cylinders, heads, secs;
538 static int virtio_blk_id;
2930b313 539 DriveInfo *dinfo;
cf21e106 540
d75d25e3
MA
541 if (!conf->bs) {
542 error_report("virtio-blk-pci: drive property not set");
543 return NULL;
544 }
98f28ad7
MA
545 if (!bdrv_is_inserted(conf->bs)) {
546 error_report("Device needs media, but drive is empty");
547 return NULL;
548 }
d75d25e3 549
53c25cea 550 s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
37d5ddd6 551 sizeof(struct virtio_blk_config),
53c25cea 552 sizeof(VirtIOBlock));
6e02c38d
AL
553
554 s->vdev.get_config = virtio_blk_update_config;
555 s->vdev.get_features = virtio_blk_get_features;
556 s->vdev.reset = virtio_blk_reset;
f8b6cc00 557 s->bs = conf->bs;
9752c371 558 s->conf = conf;
869a5c6d 559 s->rq = NULL;
1573a35d 560 s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
6e02c38d 561 bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
6e02c38d 562
2930b313 563 /* NB: per existing s/n string convention the string is terminated
564 * by '\0' only when less than sizeof (s->sn)
565 */
566 dinfo = drive_get_by_blockdev(s->bs);
567 strncpy(s->sn, dinfo->serial, sizeof (s->sn));
568
6e02c38d
AL
569 s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output);
570
869a5c6d 571 qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
9d0d3138 572 s->qdev = dev;
0be71e32 573 register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
6e02c38d 574 virtio_blk_save, virtio_blk_load, s);
7d0d6950 575 bdrv_set_removable(s->bs, 0);
e5051fc7 576 bdrv_set_change_cb(s->bs, virtio_blk_change_cb, s);
316a7af3 577 s->bs->buffer_alignment = conf->logical_block_size;
6e02c38d 578
1ca4d09a
GN
579 add_boot_device_path(conf->bootindex, dev, "/disk@0,0");
580
53c25cea 581 return &s->vdev;
6e02c38d 582}
9d0d3138
AW
583
584void virtio_blk_exit(VirtIODevice *vdev)
585{
586 VirtIOBlock *s = to_virtio_blk(vdev);
587 unregister_savevm(s->qdev, "virtio-blk", s);
588}