1
Description: fix denial of service via virtio device hot-plugging
2
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=0b81c1ef5c677c2a07be5f8bf0dfe2c62ef52115
3
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=06d3dff0723c712a4b109ced4243edf49ef850af
4
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=f24a684073bcdaf4e9d3c592345744ba3356d9e3
5
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=a3fc66d9fd37acbfcee013692246a8ae42bd93bb
6
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=5e96f5d2f8d2696ef7d2d8d7282c18fa6023470b
7
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=40dfc16f5fe0afb66f9436718781264dfadb6c61
8
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=0e86c13fe2058adb8c792ebb7c51a6a7ca9d3d55
9
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=3786cff5eb384d058395a2729af627fa3253d056
10
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=e3c9d76acc984218264bbc6435b0c09f959ed9b8
11
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=baa61b9870dd7e0bb07e0ae61c6ec805db13f699
12
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=7bb6edb0e3dd78d74e0ac980cf6c0a07307f61bf
13
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=06a1307379fcd6c551185ad87679cd7ed896b9ea
14
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=3ffeeef735fdb52ffee2eed4fb398f3a1199728f
15
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=0f3657ec3664b340ae20b461a7e15dbdac129179
16
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=179b417e17ada41dce4e8112bea0a78a70b6162c
17
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=b1a20c3fcab96832c3813e9e7162748f325e0c82
18
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=284a32f0b33dce4e77e896168387b8dca90c4bea
19
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=a546fb174162b0186fe6c275476cb45e5cafa68c
20
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=af7671fdc530dd597b1ddb4561f5ffc0d534c44c
21
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=7598f0f30e027146ba70517a2bda98d16bac1e24
22
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=1d244b42d200c02ad60eb564c75d8adea9243366
23
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=59be75227d3985c9f0a9f5396fc64e357a54defb
24
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=75884afd5c6c42e523b08565e289dbe319e17ad9
25
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=863462440d646098d2b83fb0ffa5f165e7f90511
26
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=e6f746b380ad04246e5cce621f174355f39addcd
27
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=74def47c8c1453a48f9bd61633050cc681e67fba
28
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=a8d57dfb28bd8fd8ebddf08d0cfafdcb61a764fb
29
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=71a6520b83414b4ebe3ecfdee3dc3a70db98c91f
30
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=0ba94b6f94a5b0bed9f125ce4c3348adc83db5de
31
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=306ec6c3cece7004429c79c1ac93d49919f1f1cc
32
Origin: upstream, http://git.qemu.org/?p=qemu.git;a=commit;h=83d0704734955bf1aa7697af7be2a50e11a80a42
34
Index: qemu-1.7.0+dfsg/hw/9pfs/virtio-9p-device.c
35
===================================================================
36
--- qemu-1.7.0+dfsg.orig/hw/9pfs/virtio-9p-device.c 2014-01-27 09:09:34.414970261 -0500
37
+++ qemu-1.7.0+dfsg/hw/9pfs/virtio-9p-device.c 2014-01-27 09:09:34.402970260 -0500
42
-static int virtio_9p_device_init(VirtIODevice *vdev)
43
+static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
45
- V9fsState *s = VIRTIO_9P(vdev);
46
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
47
+ V9fsState *s = VIRTIO_9P(dev);
53
- virtio_init(VIRTIO_DEVICE(s), "virtio-9p", VIRTIO_ID_9P,
54
+ virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P,
55
sizeof(struct virtio_9p_config) + MAX_TAG_LEN);
57
/* initialize pdu allocator */
61
/* We don't have a fsdev identified by fsdev_id */
62
- fprintf(stderr, "Virtio-9p device couldn't find fsdev with the "
64
- s->fsconf.fsdev_id ? s->fsconf.fsdev_id : "NULL");
65
+ error_setg(errp, "Virtio-9p device couldn't find fsdev with the "
67
+ s->fsconf.fsdev_id ? s->fsconf.fsdev_id : "NULL");
72
/* we haven't specified a mount_tag */
73
- fprintf(stderr, "fsdev with id %s needs mount_tag arguments\n",
74
- s->fsconf.fsdev_id);
75
+ error_setg(errp, "fsdev with id %s needs mount_tag arguments",
76
+ s->fsconf.fsdev_id);
81
s->ctx.exops.get_st_gen = NULL;
82
len = strlen(s->fsconf.tag);
83
if (len > MAX_TAG_LEN - 1) {
84
- fprintf(stderr, "mount tag '%s' (%d bytes) is longer than "
85
- "maximum (%d bytes)", s->fsconf.tag, len, MAX_TAG_LEN - 1);
86
+ error_setg(errp, "mount tag '%s' (%d bytes) is longer than "
87
+ "maximum (%d bytes)", s->fsconf.tag, len, MAX_TAG_LEN - 1);
92
qemu_co_rwlock_init(&s->rename_lock);
94
if (s->ops->init(&s->ctx) < 0) {
95
- fprintf(stderr, "Virtio-9p Failed to initialize fs-driver with id:%s"
96
- " and export path:%s\n", s->fsconf.fsdev_id, s->ctx.fs_root);
97
+ error_setg(errp, "Virtio-9p Failed to initialize fs-driver with id:%s"
98
+ " and export path:%s", s->fsconf.fsdev_id, s->ctx.fs_root);
101
if (v9fs_init_worker_threads() < 0) {
102
- fprintf(stderr, "worker thread initialization failed\n");
103
+ error_setg(errp, "worker thread initialization failed");
107
@@ -114,28 +115,25 @@
108
* use co-routines here.
110
if (s->ops->name_to_path(&s->ctx, NULL, "/", &path) < 0) {
112
- "error in converting name to path %s", strerror(errno));
114
+ "error in converting name to path %s", strerror(errno));
117
if (s->ops->lstat(&s->ctx, &path, &stat)) {
118
- fprintf(stderr, "share path %s does not exist\n", fse->path);
119
+ error_setg(errp, "share path %s does not exist", fse->path);
121
} else if (!S_ISDIR(stat.st_mode)) {
122
- fprintf(stderr, "share path %s is not a directory\n", fse->path);
123
+ error_setg(errp, "share path %s is not a directory", fse->path);
126
v9fs_path_free(&path);
131
g_free(s->ctx.fs_root);
133
virtio_cleanup(vdev);
134
v9fs_path_free(&path);
140
/* virtio-9p device */
143
DeviceClass *dc = DEVICE_CLASS(klass);
144
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
146
dc->props = virtio_9p_properties;
147
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
148
- vdc->init = virtio_9p_device_init;
149
+ vdc->realize = virtio_9p_device_realize;
150
vdc->get_features = virtio_9p_get_features;
151
vdc->get_config = virtio_9p_get_config;
153
Index: qemu-1.7.0+dfsg/hw/block/dataplane/virtio-blk.c
154
===================================================================
155
--- qemu-1.7.0+dfsg.orig/hw/block/dataplane/virtio-blk.c 2014-01-27 09:09:34.414970261 -0500
156
+++ qemu-1.7.0+dfsg/hw/block/dataplane/virtio-blk.c 2014-01-27 09:09:34.406970261 -0500
158
s, QEMU_THREAD_JOINABLE);
161
-bool virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
162
- VirtIOBlockDataPlane **dataplane)
163
+void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
164
+ VirtIOBlockDataPlane **dataplane,
167
VirtIOBlockDataPlane *s;
169
@@ -389,33 +390,35 @@
172
if (!blk->data_plane) {
178
- error_report("device is incompatible with x-data-plane, use scsi=off");
181
+ "device is incompatible with x-data-plane, use scsi=off");
185
if (blk->config_wce) {
186
- error_report("device is incompatible with x-data-plane, "
187
- "use config-wce=off");
189
+ error_setg(errp, "device is incompatible with x-data-plane, "
190
+ "use config-wce=off");
194
/* If dataplane is (re-)enabled while the guest is running there could be
195
* block jobs that can conflict.
197
if (bdrv_in_use(blk->conf.bs)) {
198
- error_report("cannot start dataplane thread while device is in use");
201
+ "cannot start dataplane thread while device is in use");
205
fd = raw_get_aio_fd(blk->conf.bs);
207
- error_report("drive is incompatible with x-data-plane, "
208
- "use format=raw,cache=none,aio=native");
210
+ error_setg(errp, "drive is incompatible with x-data-plane, "
211
+ "use format=raw,cache=none,aio=native");
215
s = g_new0(VirtIOBlockDataPlane, 1);
217
bdrv_set_in_use(blk->conf.bs, 1);
223
void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)
224
Index: qemu-1.7.0+dfsg/hw/block/dataplane/virtio-blk.h
225
===================================================================
226
--- qemu-1.7.0+dfsg.orig/hw/block/dataplane/virtio-blk.h 2014-01-27 09:09:34.414970261 -0500
227
+++ qemu-1.7.0+dfsg/hw/block/dataplane/virtio-blk.h 2014-01-27 09:09:34.406970261 -0500
230
typedef struct VirtIOBlockDataPlane VirtIOBlockDataPlane;
232
-bool virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
233
- VirtIOBlockDataPlane **dataplane);
234
+void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
235
+ VirtIOBlockDataPlane **dataplane,
237
void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s);
238
void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s);
239
void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s);
240
Index: qemu-1.7.0+dfsg/hw/block/virtio-blk.c
241
===================================================================
242
--- qemu-1.7.0+dfsg.orig/hw/block/virtio-blk.c 2014-01-27 09:09:34.414970261 -0500
243
+++ qemu-1.7.0+dfsg/hw/block/virtio-blk.c 2014-01-27 09:09:34.406970261 -0500
245
VirtIOBlock *s = container_of(notifier, VirtIOBlock,
246
migration_state_notifier);
247
MigrationState *mig = data;
250
if (migration_in_setup(mig)) {
252
@@ -671,31 +672,39 @@
254
bdrv_drain_all(); /* complete in-flight non-dataplane requests */
255
virtio_blk_data_plane_create(VIRTIO_DEVICE(s), &s->blk,
257
+ &s->dataplane, &err);
259
+ error_report("%s", error_get_pretty(err));
264
#endif /* CONFIG_VIRTIO_BLK_DATA_PLANE */
266
-static int virtio_blk_device_init(VirtIODevice *vdev)
267
+static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
269
- DeviceState *qdev = DEVICE(vdev);
270
- VirtIOBlock *s = VIRTIO_BLK(vdev);
271
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
272
+ VirtIOBlock *s = VIRTIO_BLK(dev);
273
VirtIOBlkConf *blk = &(s->blk);
274
+#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
277
static int virtio_blk_id;
280
- error_report("drive property not set");
282
+ error_setg(errp, "drive property not set");
285
if (!bdrv_is_inserted(blk->conf.bs)) {
286
- error_report("Device needs media, but drive is empty");
288
+ error_setg(errp, "Device needs media, but drive is empty");
292
blkconf_serial(&blk->conf, &blk->serial);
293
s->original_wce = bdrv_enable_write_cache(blk->conf.bs);
294
if (blkconf_geometry(&blk->conf, NULL, 65535, 255, 255) < 0) {
296
+ error_setg(errp, "Error setting geometry");
300
virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
301
@@ -708,30 +717,32 @@
303
s->vq = virtio_add_queue(vdev, 128, virtio_blk_handle_output);
304
#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
305
- if (!virtio_blk_data_plane_create(vdev, blk, &s->dataplane)) {
306
+ virtio_blk_data_plane_create(vdev, blk, &s->dataplane, &err);
308
+ error_propagate(errp, err);
309
virtio_cleanup(vdev);
313
s->migration_state_notifier.notify = virtio_blk_migration_state_changed;
314
add_migration_state_change_notifier(&s->migration_state_notifier);
317
s->change = qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
318
- register_savevm(qdev, "virtio-blk", virtio_blk_id++, 2,
319
+ register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
320
virtio_blk_save, virtio_blk_load, s);
321
bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
322
bdrv_set_buffer_alignment(s->bs, s->conf->logical_block_size);
324
bdrv_iostatus_enable(s->bs);
326
- add_boot_device_path(s->conf->bootindex, qdev, "/disk@0,0");
328
+ add_boot_device_path(s->conf->bootindex, dev, "/disk@0,0");
331
-static int virtio_blk_device_exit(DeviceState *dev)
332
+static void virtio_blk_device_unrealize(DeviceState *dev, Error **errp)
334
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
335
VirtIOBlock *s = VIRTIO_BLK(dev);
337
#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
338
remove_migration_state_change_notifier(&s->migration_state_notifier);
339
virtio_blk_data_plane_destroy(s->dataplane);
341
unregister_savevm(dev, "virtio-blk", s);
342
blockdev_mark_auto_del(s->bs);
343
virtio_cleanup(vdev);
347
static Property virtio_blk_properties[] = {
348
@@ -753,10 +763,11 @@
350
DeviceClass *dc = DEVICE_CLASS(klass);
351
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
352
- dc->exit = virtio_blk_device_exit;
354
dc->props = virtio_blk_properties;
355
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
356
- vdc->init = virtio_blk_device_init;
357
+ vdc->realize = virtio_blk_device_realize;
358
+ vdc->unrealize = virtio_blk_device_unrealize;
359
vdc->get_config = virtio_blk_update_config;
360
vdc->set_config = virtio_blk_set_config;
361
vdc->get_features = virtio_blk_get_features;
362
Index: qemu-1.7.0+dfsg/hw/char/virtio-serial-bus.c
363
===================================================================
364
--- qemu-1.7.0+dfsg.orig/hw/char/virtio-serial-bus.c 2014-01-27 09:09:34.414970261 -0500
365
+++ qemu-1.7.0+dfsg/hw/char/virtio-serial-bus.c 2014-01-27 09:09:34.406970261 -0500
366
@@ -889,22 +889,24 @@
370
-static int virtio_serial_device_init(VirtIODevice *vdev)
371
+static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
373
- DeviceState *qdev = DEVICE(vdev);
374
- VirtIOSerial *vser = VIRTIO_SERIAL(vdev);
375
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
376
+ VirtIOSerial *vser = VIRTIO_SERIAL(dev);
378
uint32_t i, max_supported_ports;
380
if (!vser->serial.max_virtserial_ports) {
382
+ error_setg(errp, "Maximum number of serial ports not specified");
386
/* Each port takes 2 queues, and one pair is for the control queue */
387
max_supported_ports = VIRTIO_PCI_QUEUE_MAX / 2 - 1;
389
if (vser->serial.max_virtserial_ports > max_supported_ports) {
390
- error_report("maximum ports supported: %u", max_supported_ports);
392
+ error_setg(errp, "maximum ports supported: %u", max_supported_ports);
396
virtio_init(vdev, "virtio-serial", VIRTIO_ID_CONSOLE,
399
/* Spawn a new virtio-serial bus on which the ports will ride as devices */
400
qbus_create_inplace(&vser->bus, sizeof(vser->bus), TYPE_VIRTIO_SERIAL_BUS,
401
- qdev, vdev->bus_name);
402
- vser->bus.qbus.allow_hotplug = 1;
403
+ dev, vdev->bus_name);
404
+ bus = BUS(&vser->bus);
405
+ bus->allow_hotplug = 1;
406
vser->bus.vser = vser;
407
QTAILQ_INIT(&vser->ports);
410
* Register for the savevm section with the virtio-console name
411
* to preserve backward compat
413
- register_savevm(qdev, "virtio-console", -1, 3, virtio_serial_save,
414
+ register_savevm(dev, "virtio-console", -1, 3, virtio_serial_save,
415
virtio_serial_load, vser);
420
static void virtio_serial_port_class_init(ObjectClass *klass, void *data)
421
@@ -987,10 +988,10 @@
422
.class_init = virtio_serial_port_class_init,
425
-static int virtio_serial_device_exit(DeviceState *dev)
426
+static void virtio_serial_device_unrealize(DeviceState *dev, Error **errp)
428
- VirtIOSerial *vser = VIRTIO_SERIAL(dev);
429
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
430
+ VirtIOSerial *vser = VIRTIO_SERIAL(dev);
432
unregister_savevm(dev, "virtio-console", vser);
434
@@ -1004,7 +1005,6 @@
435
g_free(vser->post_load);
437
virtio_cleanup(vdev);
441
static Property virtio_serial_properties[] = {
442
@@ -1016,10 +1016,11 @@
444
DeviceClass *dc = DEVICE_CLASS(klass);
445
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
446
- dc->exit = virtio_serial_device_exit;
448
dc->props = virtio_serial_properties;
449
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
450
- vdc->init = virtio_serial_device_init;
451
+ vdc->realize = virtio_serial_device_realize;
452
+ vdc->unrealize = virtio_serial_device_unrealize;
453
vdc->get_features = get_features;
454
vdc->get_config = get_config;
455
vdc->set_config = set_config;
456
Index: qemu-1.7.0+dfsg/hw/net/virtio-net.c
457
===================================================================
458
--- qemu-1.7.0+dfsg.orig/hw/net/virtio-net.c 2014-01-27 09:09:34.414970261 -0500
459
+++ qemu-1.7.0+dfsg/hw/net/virtio-net.c 2014-01-27 09:09:34.406970261 -0500
460
@@ -1486,16 +1486,14 @@
461
n->netclient_type = g_strdup(type);
464
-static int virtio_net_device_init(VirtIODevice *vdev)
465
+static void virtio_net_device_realize(DeviceState *dev, Error **errp)
469
- DeviceState *qdev = DEVICE(vdev);
470
- VirtIONet *n = VIRTIO_NET(vdev);
471
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
472
+ VirtIONet *n = VIRTIO_NET(dev);
476
- virtio_init(VIRTIO_DEVICE(n), "virtio-net", VIRTIO_ID_NET,
478
+ virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size);
480
n->max_queues = MAX(n->nic_conf.queues, 1);
481
n->vqs = g_malloc0(sizeof(VirtIONetQueue) * n->max_queues);
482
@@ -1535,7 +1533,7 @@
483
n->netclient_type, n->netclient_name, n);
485
n->nic = qemu_new_nic(&net_virtio_info, &n->nic_conf,
486
- object_get_typename(OBJECT(qdev)), qdev->id, n);
487
+ object_get_typename(OBJECT(dev)), dev->id, n);
490
peer_test_vnet_hdr(n);
491
@@ -1562,24 +1560,23 @@
492
nc = qemu_get_queue(n->nic);
493
nc->rxfilter_notify_enabled = 1;
496
- register_savevm(qdev, "virtio-net", -1, VIRTIO_NET_VM_VERSION,
498
+ register_savevm(dev, "virtio-net", -1, VIRTIO_NET_VM_VERSION,
499
virtio_net_save, virtio_net_load, n);
501
- add_boot_device_path(n->nic_conf.bootindex, qdev, "/ethernet-phy@0");
503
+ add_boot_device_path(n->nic_conf.bootindex, dev, "/ethernet-phy@0");
506
-static int virtio_net_device_exit(DeviceState *qdev)
507
+static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
509
- VirtIONet *n = VIRTIO_NET(qdev);
510
- VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
511
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
512
+ VirtIONet *n = VIRTIO_NET(dev);
515
/* This will stop vhost backend if appropriate. */
516
virtio_net_set_status(vdev, 0);
518
- unregister_savevm(qdev, "virtio-net", n);
519
+ unregister_savevm(dev, "virtio-net", n);
521
if (n->netclient_name) {
522
g_free(n->netclient_name);
523
@@ -1610,8 +1607,6 @@
525
qemu_del_nic(n->nic);
526
virtio_cleanup(vdev);
531
static void virtio_net_instance_init(Object *obj)
532
@@ -1638,10 +1633,11 @@
534
DeviceClass *dc = DEVICE_CLASS(klass);
535
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
536
- dc->exit = virtio_net_device_exit;
538
dc->props = virtio_net_properties;
539
set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
540
- vdc->init = virtio_net_device_init;
541
+ vdc->realize = virtio_net_device_realize;
542
+ vdc->unrealize = virtio_net_device_unrealize;
543
vdc->get_config = virtio_net_get_config;
544
vdc->set_config = virtio_net_set_config;
545
vdc->get_features = virtio_net_get_features;
546
Index: qemu-1.7.0+dfsg/hw/s390x/virtio-ccw.c
547
===================================================================
548
--- qemu-1.7.0+dfsg.orig/hw/s390x/virtio-ccw.c 2014-01-27 09:09:34.414970261 -0500
549
+++ qemu-1.7.0+dfsg/hw/s390x/virtio-ccw.c 2014-01-27 09:09:34.406970261 -0500
551
VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
553
VirtIODevice *vdev = NULL;
554
+ VirtioCcwDevice *dev = sch->driver_data;
556
- if (sch->driver_data) {
557
- vdev = ((VirtioCcwDevice *)sch->driver_data)->vdev;
559
+ vdev = virtio_bus_get_device(&dev->bus);
564
static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,
565
bool assign, bool set_handler)
567
- VirtQueue *vq = virtio_get_queue(dev->vdev, n);
568
+ VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
569
+ VirtQueue *vq = virtio_get_queue(vdev, n);
570
EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
572
SubchDev *sch = dev->sch;
575
static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
577
+ VirtIODevice *vdev;
580
if (!(dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) ||
582
dev->ioeventfd_started) {
585
+ vdev = virtio_bus_get_device(&dev->bus);
586
for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
587
- if (!virtio_queue_get_num(dev->vdev, n)) {
588
+ if (!virtio_queue_get_num(vdev, n)) {
591
r = virtio_ccw_set_guest2host_notifier(dev, n, true, true);
596
- if (!virtio_queue_get_num(dev->vdev, n)) {
597
+ if (!virtio_queue_get_num(vdev, n)) {
600
r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
601
@@ -132,13 +136,15 @@
603
static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev)
605
+ VirtIODevice *vdev;
608
if (!dev->ioeventfd_started) {
611
+ vdev = virtio_bus_get_device(&dev->bus);
612
for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
613
- if (!virtio_queue_get_num(dev->vdev, n)) {
614
+ if (!virtio_queue_get_num(vdev, n)) {
617
r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
619
static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,
620
uint16_t index, uint16_t num)
622
- VirtioCcwDevice *dev = sch->driver_data;
623
+ VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
625
if (index > VIRTIO_PCI_QUEUE_MAX) {
627
@@ -200,23 +206,23 @@
636
- virtio_queue_set_addr(dev->vdev, index, addr);
637
+ virtio_queue_set_addr(vdev, index, addr);
639
- virtio_queue_set_vector(dev->vdev, index, 0);
640
+ virtio_queue_set_vector(vdev, index, 0);
642
/* Fail if we don't have a big enough queue. */
643
/* TODO: Add interface to handle vring.num changing */
644
- if (virtio_queue_get_num(dev->vdev, index) > num) {
645
+ if (virtio_queue_get_num(vdev, index) > num) {
648
- virtio_queue_set_vector(dev->vdev, index, index);
649
+ virtio_queue_set_vector(vdev, index, index);
651
/* tell notify handler in case of config change */
652
- dev->vdev->config_vector = VIRTIO_PCI_QUEUE_MAX;
653
+ vdev->config_vector = VIRTIO_PCI_QUEUE_MAX;
659
VqConfigBlock vq_config;
660
VirtioCcwDevice *dev = sch->driver_data;
661
+ VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
667
case CCW_CMD_VDEV_RESET:
668
virtio_ccw_stop_ioeventfd(dev);
669
- virtio_reset(dev->vdev);
670
+ virtio_reset(vdev);
673
case CCW_CMD_READ_FEAT:
675
features.features = ldl_le_phys(ccw.cda);
676
if (features.index < ARRAY_SIZE(dev->host_features)) {
677
virtio_bus_set_vdev_features(&dev->bus, features.features);
678
- dev->vdev->guest_features = features.features;
679
+ vdev->guest_features = features.features;
682
* If the guest supports more feature bits, assert that it
683
@@ -337,30 +344,30 @@
685
case CCW_CMD_READ_CONF:
687
- if (ccw.count > dev->vdev->config_len) {
688
+ if (ccw.count > vdev->config_len) {
693
- len = MIN(ccw.count, dev->vdev->config_len);
694
+ len = MIN(ccw.count, vdev->config_len);
698
- virtio_bus_get_vdev_config(&dev->bus, dev->vdev->config);
699
+ virtio_bus_get_vdev_config(&dev->bus, vdev->config);
700
/* XXX config space endianness */
701
- cpu_physical_memory_write(ccw.cda, dev->vdev->config, len);
702
+ cpu_physical_memory_write(ccw.cda, vdev->config, len);
703
sch->curr_status.scsw.count = ccw.count - len;
707
case CCW_CMD_WRITE_CONF:
709
- if (ccw.count > dev->vdev->config_len) {
710
+ if (ccw.count > vdev->config_len) {
715
- len = MIN(ccw.count, dev->vdev->config_len);
716
+ len = MIN(ccw.count, vdev->config_len);
723
/* XXX config space endianness */
724
- memcpy(dev->vdev->config, config, len);
725
+ memcpy(vdev->config, config, len);
726
cpu_physical_memory_unmap(config, hw_len, 0, hw_len);
727
- virtio_bus_set_vdev_config(&dev->bus, dev->vdev->config);
728
+ virtio_bus_set_vdev_config(&dev->bus, vdev->config);
729
sch->curr_status.scsw.count = ccw.count - len;
733
if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
734
virtio_ccw_stop_ioeventfd(dev);
736
- virtio_set_status(dev->vdev, status);
737
- if (dev->vdev->status == 0) {
738
- virtio_reset(dev->vdev);
739
+ virtio_set_status(vdev, status);
740
+ if (vdev->status == 0) {
741
+ virtio_reset(vdev);
743
if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
744
virtio_ccw_start_ioeventfd(dev);
748
vq_config.index = lduw_phys(ccw.cda);
749
- vq_config.num_max = virtio_queue_get_num(dev->vdev,
750
+ vq_config.num_max = virtio_queue_get_num(vdev,
752
stw_phys(ccw.cda + sizeof(vq_config.index), vq_config.num_max);
753
sch->curr_status.scsw.count = ccw.count - sizeof(vq_config);
755
sch->driver_data = dev;
761
/* Initialize subchannel structure. */
763
memset(&sch->id, 0, sizeof(SenseId));
764
sch->id.reserved = 0xff;
765
sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
766
- sch->id.cu_model = dev->vdev->device_id;
767
+ sch->id.cu_model = vdev->device_id;
769
/* Only the first 32 feature bits are used. */
770
dev->host_features[0] = virtio_bus_get_vdev_features(&dev->bus,
773
SubchDev *sch = dev->sch;
775
- virtio_ccw_stop_ioeventfd(dev);
777
css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
780
static void virtio_ccw_reset(DeviceState *d)
782
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
783
+ VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
785
virtio_ccw_stop_ioeventfd(dev);
786
- virtio_reset(dev->vdev);
787
+ virtio_reset(vdev);
788
css_reset_sch(dev->sch);
790
dev->indicators2 = 0;
792
static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
793
bool assign, bool with_irqfd)
795
- VirtQueue *vq = virtio_get_queue(dev->vdev, n);
796
+ VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
797
+ VirtQueue *vq = virtio_get_queue(vdev, n);
798
EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
799
- VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(dev->vdev);
800
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
803
int r = event_notifier_init(notifier, 0);
804
@@ -952,16 +959,16 @@
805
* land in qemu (and only the irq fd) in this code.
807
if (k->guest_notifier_mask) {
808
- k->guest_notifier_mask(dev->vdev, n, false);
809
+ k->guest_notifier_mask(vdev, n, false);
811
/* get lost events and re-inject */
812
if (k->guest_notifier_pending &&
813
- k->guest_notifier_pending(dev->vdev, n)) {
814
+ k->guest_notifier_pending(vdev, n)) {
815
event_notifier_set(notifier);
818
if (k->guest_notifier_mask) {
819
- k->guest_notifier_mask(dev->vdev, n, true);
820
+ k->guest_notifier_mask(vdev, n, true);
822
virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
823
event_notifier_cleanup(notifier);
827
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
828
- VirtIODevice *vdev = dev->vdev;
829
+ VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
832
for (n = 0; n < nvqs; n++) {
833
@@ -1228,6 +1235,8 @@
834
VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
835
SubchDev *sch = _dev->sch;
837
+ virtio_ccw_stop_ioeventfd(_dev);
840
* We should arrive here only for device_del, since we don't support
841
* direct hot(un)plug of channels, but only through virtio.
842
Index: qemu-1.7.0+dfsg/hw/s390x/virtio-ccw.h
843
===================================================================
844
--- qemu-1.7.0+dfsg.orig/hw/s390x/virtio-ccw.h 2014-01-27 09:09:34.414970261 -0500
845
+++ qemu-1.7.0+dfsg/hw/s390x/virtio-ccw.h 2014-01-27 09:09:34.406970261 -0500
847
struct VirtioCcwDevice {
848
DeviceState parent_obj;
850
- VirtIODevice *vdev;
852
uint32_t host_features[VIRTIO_CCW_FEATURE_SIZE];
854
Index: qemu-1.7.0+dfsg/hw/scsi/vhost-scsi.c
855
===================================================================
856
--- qemu-1.7.0+dfsg.orig/hw/scsi/vhost-scsi.c 2014-01-27 09:09:34.414970261 -0500
857
+++ qemu-1.7.0+dfsg/hw/scsi/vhost-scsi.c 2014-01-27 09:09:34.406970261 -0500
858
@@ -196,29 +196,31 @@
862
-static int vhost_scsi_init(VirtIODevice *vdev)
863
+static void vhost_scsi_realize(DeviceState *dev, Error **errp)
865
- VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
866
- VHostSCSI *s = VHOST_SCSI(vdev);
867
+ VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
868
+ VHostSCSI *s = VHOST_SCSI(dev);
873
if (!vs->conf.wwpn) {
874
- error_report("vhost-scsi: missing wwpn\n");
876
+ error_setg(errp, "vhost-scsi: missing wwpn");
880
if (vs->conf.vhostfd) {
881
vhostfd = monitor_handle_fd_param(cur_mon, vs->conf.vhostfd);
883
- error_report("vhost-scsi: unable to parse vhostfd\n");
885
+ error_setg(errp, "vhost-scsi: unable to parse vhostfd");
890
- ret = virtio_scsi_common_init(vs);
893
+ virtio_scsi_common_realize(dev, &err);
895
+ error_propagate(errp, err);
899
s->dev.nvqs = VHOST_SCSI_VQ_NUM_FIXED + vs->conf.num_queues;
900
@@ -227,24 +229,21 @@
902
ret = vhost_dev_init(&s->dev, vhostfd, "/dev/vhost-scsi", true);
904
- error_report("vhost-scsi: vhost initialization failed: %s\n",
907
+ error_setg(errp, "vhost-scsi: vhost initialization failed: %s",
911
s->dev.backend_features = 0;
913
error_setg(&s->migration_blocker,
914
"vhost-scsi does not support migration");
915
migrate_add_blocker(s->migration_blocker);
920
-static int vhost_scsi_exit(DeviceState *qdev)
921
+static void vhost_scsi_unrealize(DeviceState *dev, Error **errp)
923
- VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
924
- VHostSCSI *s = VHOST_SCSI(qdev);
925
- VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(qdev);
926
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
927
+ VHostSCSI *s = VHOST_SCSI(dev);
929
migrate_del_blocker(s->migration_blocker);
930
error_free(s->migration_blocker);
932
vhost_scsi_set_status(vdev, 0);
935
- return virtio_scsi_common_exit(vs);
937
+ virtio_scsi_common_unrealize(dev, errp);
940
static Property vhost_scsi_properties[] = {
941
@@ -265,10 +265,11 @@
943
DeviceClass *dc = DEVICE_CLASS(klass);
944
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
945
- dc->exit = vhost_scsi_exit;
947
dc->props = vhost_scsi_properties;
948
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
949
- vdc->init = vhost_scsi_init;
950
+ vdc->realize = vhost_scsi_realize;
951
+ vdc->unrealize = vhost_scsi_unrealize;
952
vdc->get_features = vhost_scsi_get_features;
953
vdc->set_config = vhost_scsi_set_config;
954
vdc->set_status = vhost_scsi_set_status;
955
Index: qemu-1.7.0+dfsg/hw/scsi/virtio-scsi.c
956
===================================================================
957
--- qemu-1.7.0+dfsg.orig/hw/scsi/virtio-scsi.c 2014-01-27 09:09:34.414970261 -0500
958
+++ qemu-1.7.0+dfsg/hw/scsi/virtio-scsi.c 2014-01-27 09:09:34.406970261 -0500
959
@@ -589,12 +589,13 @@
960
.load_request = virtio_scsi_load_request,
963
-int virtio_scsi_common_init(VirtIOSCSICommon *s)
964
+void virtio_scsi_common_realize(DeviceState *dev, Error **errp)
966
- VirtIODevice *vdev = VIRTIO_DEVICE(s);
967
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
968
+ VirtIOSCSICommon *s = VIRTIO_SCSI_COMMON(dev);
971
- virtio_init(VIRTIO_DEVICE(s), "virtio-scsi", VIRTIO_ID_SCSI,
972
+ virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI,
973
sizeof(VirtIOSCSIConfig));
975
s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *));
976
@@ -609,57 +610,52 @@
977
s->cmd_vqs[i] = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE,
978
virtio_scsi_handle_cmd);
984
-static int virtio_scsi_device_init(VirtIODevice *vdev)
985
+static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
987
- DeviceState *qdev = DEVICE(vdev);
988
- VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
989
- VirtIOSCSI *s = VIRTIO_SCSI(vdev);
990
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
991
+ VirtIOSCSI *s = VIRTIO_SCSI(dev);
992
static int virtio_scsi_id;
996
- ret = virtio_scsi_common_init(vs);
999
+ virtio_scsi_common_realize(dev, &err);
1000
+ if (err != NULL) {
1001
+ error_propagate(errp, err);
1005
- scsi_bus_new(&s->bus, sizeof(s->bus), qdev,
1006
+ scsi_bus_new(&s->bus, sizeof(s->bus), dev,
1007
&virtio_scsi_scsi_info, vdev->bus_name);
1009
- if (!qdev->hotplugged) {
1010
+ if (!dev->hotplugged) {
1011
scsi_bus_legacy_handle_cmdline(&s->bus, &err);
1015
+ error_propagate(errp, err);
1020
- register_savevm(qdev, "virtio-scsi", virtio_scsi_id++, 1,
1021
+ register_savevm(dev, "virtio-scsi", virtio_scsi_id++, 1,
1022
virtio_scsi_save, virtio_scsi_load, s);
1027
-int virtio_scsi_common_exit(VirtIOSCSICommon *vs)
1028
+void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp)
1030
- VirtIODevice *vdev = VIRTIO_DEVICE(vs);
1031
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
1032
+ VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
1034
g_free(vs->cmd_vqs);
1035
virtio_cleanup(vdev);
1039
-static int virtio_scsi_device_exit(DeviceState *qdev)
1040
+static void virtio_scsi_device_unrealize(DeviceState *dev, Error **errp)
1042
- VirtIOSCSI *s = VIRTIO_SCSI(qdev);
1043
- VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(qdev);
1044
+ VirtIOSCSI *s = VIRTIO_SCSI(dev);
1046
- unregister_savevm(qdev, "virtio-scsi", s);
1047
- return virtio_scsi_common_exit(vs);
1048
+ unregister_savevm(dev, "virtio-scsi", s);
1050
+ virtio_scsi_common_unrealize(dev, errp);
1053
static Property virtio_scsi_properties[] = {
1054
@@ -680,10 +676,11 @@
1056
DeviceClass *dc = DEVICE_CLASS(klass);
1057
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
1058
- dc->exit = virtio_scsi_device_exit;
1060
dc->props = virtio_scsi_properties;
1061
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
1062
- vdc->init = virtio_scsi_device_init;
1063
+ vdc->realize = virtio_scsi_device_realize;
1064
+ vdc->unrealize = virtio_scsi_device_unrealize;
1065
vdc->set_config = virtio_scsi_set_config;
1066
vdc->get_features = virtio_scsi_get_features;
1067
vdc->reset = virtio_scsi_reset;
1068
Index: qemu-1.7.0+dfsg/hw/virtio/virtio-balloon.c
1069
===================================================================
1070
--- qemu-1.7.0+dfsg.orig/hw/virtio/virtio-balloon.c 2014-01-27 09:09:34.414970261 -0500
1071
+++ qemu-1.7.0+dfsg/hw/virtio/virtio-balloon.c 2014-01-27 09:09:34.410970261 -0500
1072
@@ -337,10 +337,10 @@
1076
-static int virtio_balloon_device_init(VirtIODevice *vdev)
1077
+static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
1079
- DeviceState *qdev = DEVICE(vdev);
1080
- VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
1081
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
1082
+ VirtIOBalloon *s = VIRTIO_BALLOON(dev);
1085
virtio_init(vdev, "virtio-balloon", VIRTIO_ID_BALLOON, 8);
1086
@@ -349,37 +349,36 @@
1087
virtio_balloon_stat, s);
1090
- virtio_cleanup(VIRTIO_DEVICE(s));
1092
+ error_setg(errp, "Adding balloon handler failed");
1093
+ virtio_cleanup(vdev);
1097
s->ivq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
1098
s->dvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
1099
s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats);
1101
- register_savevm(qdev, "virtio-balloon", -1, 1,
1102
+ register_savevm(dev, "virtio-balloon", -1, 1,
1103
virtio_balloon_save, virtio_balloon_load, s);
1105
- object_property_add(OBJECT(qdev), "guest-stats", "guest statistics",
1106
+ object_property_add(OBJECT(dev), "guest-stats", "guest statistics",
1107
balloon_stats_get_all, NULL, NULL, s, NULL);
1109
- object_property_add(OBJECT(qdev), "guest-stats-polling-interval", "int",
1110
+ object_property_add(OBJECT(dev), "guest-stats-polling-interval", "int",
1111
balloon_stats_get_poll_interval,
1112
balloon_stats_set_poll_interval,
1117
-static int virtio_balloon_device_exit(DeviceState *qdev)
1118
+static void virtio_balloon_device_unrealize(DeviceState *dev, Error **errp)
1120
- VirtIOBalloon *s = VIRTIO_BALLOON(qdev);
1121
- VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
1122
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
1123
+ VirtIOBalloon *s = VIRTIO_BALLOON(dev);
1125
balloon_stats_destroy_timer(s);
1126
qemu_remove_balloon_handler(s);
1127
- unregister_savevm(qdev, "virtio-balloon", s);
1128
+ unregister_savevm(dev, "virtio-balloon", s);
1129
virtio_cleanup(vdev);
1133
static Property virtio_balloon_properties[] = {
1134
@@ -390,10 +389,11 @@
1136
DeviceClass *dc = DEVICE_CLASS(klass);
1137
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
1138
- dc->exit = virtio_balloon_device_exit;
1140
dc->props = virtio_balloon_properties;
1141
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
1142
- vdc->init = virtio_balloon_device_init;
1143
+ vdc->realize = virtio_balloon_device_realize;
1144
+ vdc->unrealize = virtio_balloon_device_unrealize;
1145
vdc->get_config = virtio_balloon_get_config;
1146
vdc->set_config = virtio_balloon_set_config;
1147
vdc->get_features = virtio_balloon_get_features;
1148
Index: qemu-1.7.0+dfsg/hw/virtio/virtio-bus.c
1149
===================================================================
1150
--- qemu-1.7.0+dfsg.orig/hw/virtio/virtio-bus.c 2014-01-27 09:09:34.414970261 -0500
1151
+++ qemu-1.7.0+dfsg/hw/virtio/virtio-bus.c 2014-01-27 09:09:34.410970261 -0500
1153
#define DPRINTF(fmt, ...) do { } while (0)
1156
-/* Plug the VirtIODevice */
1157
-int virtio_bus_plug_device(VirtIODevice *vdev)
1158
+/* A VirtIODevice is being plugged */
1159
+int virtio_bus_device_plugged(VirtIODevice *vdev)
1161
DeviceState *qdev = DEVICE(vdev);
1162
BusState *qbus = BUS(qdev_get_parent_bus(qdev));
1164
VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
1165
DPRINTF("%s: plug device.\n", qbus->name);
1169
if (klass->device_plugged != NULL) {
1170
klass->device_plugged(qbus->parent);
1173
/* Reset the virtio_bus */
1174
void virtio_bus_reset(VirtioBusState *bus)
1176
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
1178
DPRINTF("%s: reset device.\n", qbus->name);
1179
- if (bus->vdev != NULL) {
1180
- virtio_reset(bus->vdev);
1181
+ if (vdev != NULL) {
1182
+ virtio_reset(vdev);
1186
-/* Destroy the VirtIODevice */
1187
-void virtio_bus_destroy_device(VirtioBusState *bus)
1188
+/* A VirtIODevice is being unplugged */
1189
+void virtio_bus_device_unplugged(VirtIODevice *vdev)
1191
- BusState *qbus = BUS(bus);
1192
- VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
1193
+ DeviceState *qdev = DEVICE(vdev);
1194
+ BusState *qbus = BUS(qdev_get_parent_bus(qdev));
1195
+ VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(qbus);
1197
DPRINTF("%s: remove device.\n", qbus->name);
1199
- if (bus->vdev != NULL) {
1200
- if (klass->device_unplug != NULL) {
1201
- klass->device_unplug(qbus->parent);
1202
+ if (vdev != NULL) {
1203
+ if (klass->device_unplugged != NULL) {
1204
+ klass->device_unplugged(qbus->parent);
1206
- object_unparent(OBJECT(bus->vdev));
1211
/* Get the device id of the plugged device. */
1212
uint16_t virtio_bus_get_vdev_id(VirtioBusState *bus)
1214
- assert(bus->vdev != NULL);
1215
- return bus->vdev->device_id;
1216
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
1217
+ assert(vdev != NULL);
1218
+ return vdev->device_id;
1221
/* Get the config_len field of the plugged device. */
1222
size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus)
1224
- assert(bus->vdev != NULL);
1225
- return bus->vdev->config_len;
1226
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
1227
+ assert(vdev != NULL);
1228
+ return vdev->config_len;
1231
/* Get the features of the plugged device. */
1232
uint32_t virtio_bus_get_vdev_features(VirtioBusState *bus,
1233
uint32_t requested_features)
1235
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
1236
VirtioDeviceClass *k;
1237
- assert(bus->vdev != NULL);
1238
- k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
1240
+ assert(vdev != NULL);
1241
+ k = VIRTIO_DEVICE_GET_CLASS(vdev);
1242
assert(k->get_features != NULL);
1243
- return k->get_features(bus->vdev, requested_features);
1244
+ return k->get_features(vdev, requested_features);
1247
/* Set the features of the plugged device. */
1248
void virtio_bus_set_vdev_features(VirtioBusState *bus,
1249
uint32_t requested_features)
1251
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
1252
VirtioDeviceClass *k;
1253
- assert(bus->vdev != NULL);
1254
- k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
1256
+ assert(vdev != NULL);
1257
+ k = VIRTIO_DEVICE_GET_CLASS(vdev);
1258
if (k->set_features != NULL) {
1259
- k->set_features(bus->vdev, requested_features);
1260
+ k->set_features(vdev, requested_features);
1264
/* Get bad features of the plugged device. */
1265
uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus)
1267
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
1268
VirtioDeviceClass *k;
1269
- assert(bus->vdev != NULL);
1270
- k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
1272
+ assert(vdev != NULL);
1273
+ k = VIRTIO_DEVICE_GET_CLASS(vdev);
1274
if (k->bad_features != NULL) {
1275
- return k->bad_features(bus->vdev);
1276
+ return k->bad_features(vdev);
1280
@@ -133,22 +141,26 @@
1281
/* Get config of the plugged device. */
1282
void virtio_bus_get_vdev_config(VirtioBusState *bus, uint8_t *config)
1284
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
1285
VirtioDeviceClass *k;
1286
- assert(bus->vdev != NULL);
1287
- k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
1289
+ assert(vdev != NULL);
1290
+ k = VIRTIO_DEVICE_GET_CLASS(vdev);
1291
if (k->get_config != NULL) {
1292
- k->get_config(bus->vdev, config);
1293
+ k->get_config(vdev, config);
1297
/* Set config of the plugged device. */
1298
void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config)
1300
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
1301
VirtioDeviceClass *k;
1302
- assert(bus->vdev != NULL);
1303
- k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
1305
+ assert(vdev != NULL);
1306
+ k = VIRTIO_DEVICE_GET_CLASS(vdev);
1307
if (k->set_config != NULL) {
1308
- k->set_config(bus->vdev, config);
1309
+ k->set_config(vdev, config);
1313
Index: qemu-1.7.0+dfsg/hw/virtio/virtio-mmio.c
1314
===================================================================
1315
--- qemu-1.7.0+dfsg.orig/hw/virtio/virtio-mmio.c 2014-01-27 09:09:34.414970261 -0500
1316
+++ qemu-1.7.0+dfsg/hw/virtio/virtio-mmio.c 2014-01-27 09:09:34.410970261 -0500
1318
static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size)
1320
VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque;
1321
- VirtIODevice *vdev = proxy->bus.vdev;
1322
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1324
DPRINTF("virtio_mmio_read offset 0x%x\n", (int)offset);
1329
VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque;
1330
- VirtIODevice *vdev = proxy->bus.vdev;
1331
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1333
DPRINTF("virtio_mmio_write offset 0x%x value 0x%" PRIx64 "\n",
1334
(int)offset, value);
1335
@@ -298,12 +298,13 @@
1336
static void virtio_mmio_update_irq(DeviceState *opaque, uint16_t vector)
1338
VirtIOMMIOProxy *proxy = VIRTIO_MMIO(opaque);
1339
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1342
- if (!proxy->bus.vdev) {
1346
- level = (proxy->bus.vdev->isr != 0);
1347
+ level = (vdev->isr != 0);
1348
DPRINTF("virtio_mmio setting IRQ %d\n", level);
1349
qemu_set_irq(proxy->irq, level);
1351
Index: qemu-1.7.0+dfsg/hw/virtio/virtio-pci.c
1352
===================================================================
1353
--- qemu-1.7.0+dfsg.orig/hw/virtio/virtio-pci.c 2014-01-27 09:09:34.414970261 -0500
1354
+++ qemu-1.7.0+dfsg/hw/virtio/virtio-pci.c 2014-01-27 09:09:34.410970261 -0500
1355
@@ -113,31 +113,40 @@
1356
static void virtio_pci_notify(DeviceState *d, uint16_t vector)
1358
VirtIOPCIProxy *proxy = to_virtio_pci_proxy_fast(d);
1360
if (msix_enabled(&proxy->pci_dev))
1361
msix_notify(&proxy->pci_dev, vector);
1363
- pci_set_irq(&proxy->pci_dev, proxy->vdev->isr & 1);
1365
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1366
+ pci_set_irq(&proxy->pci_dev, vdev->isr & 1);
1370
static void virtio_pci_save_config(DeviceState *d, QEMUFile *f)
1372
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
1373
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1375
pci_device_save(&proxy->pci_dev, f);
1376
msix_save(&proxy->pci_dev, f);
1377
if (msix_present(&proxy->pci_dev))
1378
- qemu_put_be16(f, proxy->vdev->config_vector);
1379
+ qemu_put_be16(f, vdev->config_vector);
1382
static void virtio_pci_save_queue(DeviceState *d, int n, QEMUFile *f)
1384
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
1385
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1387
if (msix_present(&proxy->pci_dev))
1388
- qemu_put_be16(f, virtio_queue_vector(proxy->vdev, n));
1389
+ qemu_put_be16(f, virtio_queue_vector(vdev, n));
1392
static int virtio_pci_load_config(DeviceState *d, QEMUFile *f)
1394
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
1395
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1398
ret = pci_device_load(&proxy->pci_dev, f);
1400
@@ -146,12 +155,12 @@
1401
msix_unuse_all_vectors(&proxy->pci_dev);
1402
msix_load(&proxy->pci_dev, f);
1403
if (msix_present(&proxy->pci_dev)) {
1404
- qemu_get_be16s(f, &proxy->vdev->config_vector);
1405
+ qemu_get_be16s(f, &vdev->config_vector);
1407
- proxy->vdev->config_vector = VIRTIO_NO_VECTOR;
1408
+ vdev->config_vector = VIRTIO_NO_VECTOR;
1410
- if (proxy->vdev->config_vector != VIRTIO_NO_VECTOR) {
1411
- return msix_vector_use(&proxy->pci_dev, proxy->vdev->config_vector);
1412
+ if (vdev->config_vector != VIRTIO_NO_VECTOR) {
1413
+ return msix_vector_use(&proxy->pci_dev, vdev->config_vector);
1417
@@ -159,13 +168,15 @@
1418
static int virtio_pci_load_queue(DeviceState *d, int n, QEMUFile *f)
1420
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
1421
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1424
if (msix_present(&proxy->pci_dev)) {
1425
qemu_get_be16s(f, &vector);
1427
vector = VIRTIO_NO_VECTOR;
1429
- virtio_queue_set_vector(proxy->vdev, n, vector);
1430
+ virtio_queue_set_vector(vdev, n, vector);
1431
if (vector != VIRTIO_NO_VECTOR) {
1432
return msix_vector_use(&proxy->pci_dev, vector);
1435
static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
1436
int n, bool assign, bool set_handler)
1438
- VirtQueue *vq = virtio_get_queue(proxy->vdev, n);
1439
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1440
+ VirtQueue *vq = virtio_get_queue(vdev, n);
1441
EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
1446
static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy)
1448
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1451
if (!(proxy->flags & VIRTIO_PCI_FLAG_USE_IOEVENTFD) ||
1455
for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
1456
- if (!virtio_queue_get_num(proxy->vdev, n)) {
1457
+ if (!virtio_queue_get_num(vdev, n)) {
1465
- if (!virtio_queue_get_num(proxy->vdev, n)) {
1466
+ if (!virtio_queue_get_num(vdev, n)) {
1472
static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
1474
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1481
for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
1482
- if (!virtio_queue_get_num(proxy->vdev, n)) {
1483
+ if (!virtio_queue_get_num(vdev, n)) {
1488
static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
1490
VirtIOPCIProxy *proxy = opaque;
1491
- VirtIODevice *vdev = proxy->vdev;
1492
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1497
pa = (hwaddr)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT;
1499
virtio_pci_stop_ioeventfd(proxy);
1500
- virtio_reset(proxy->vdev);
1501
+ virtio_reset(vdev);
1502
msix_unuse_all_vectors(&proxy->pci_dev);
1508
if (vdev->status == 0) {
1509
- virtio_reset(proxy->vdev);
1510
+ virtio_reset(vdev);
1511
msix_unuse_all_vectors(&proxy->pci_dev);
1516
static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr)
1518
- VirtIODevice *vdev = proxy->vdev;
1519
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1520
uint32_t ret = 0xFFFFFFFF;
1526
VirtIOPCIProxy *proxy = opaque;
1527
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1528
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
1530
if (addr < config) {
1531
@@ -390,16 +405,16 @@
1535
- val = virtio_config_readb(proxy->vdev, addr);
1536
+ val = virtio_config_readb(vdev, addr);
1539
- val = virtio_config_readw(proxy->vdev, addr);
1540
+ val = virtio_config_readw(vdev, addr);
1541
if (virtio_is_big_endian()) {
1546
- val = virtio_config_readl(proxy->vdev, addr);
1547
+ val = virtio_config_readl(vdev, addr);
1548
if (virtio_is_big_endian()) {
1553
VirtIOPCIProxy *proxy = opaque;
1554
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
1555
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1556
if (addr < config) {
1557
virtio_ioport_write(proxy, addr, val);
1559
@@ -424,19 +440,19 @@
1563
- virtio_config_writeb(proxy->vdev, addr, val);
1564
+ virtio_config_writeb(vdev, addr, val);
1567
if (virtio_is_big_endian()) {
1570
- virtio_config_writew(proxy->vdev, addr, val);
1571
+ virtio_config_writew(vdev, addr, val);
1574
if (virtio_is_big_endian()) {
1577
- virtio_config_writel(proxy->vdev, addr, val);
1578
+ virtio_config_writel(vdev, addr, val);
1583
uint32_t val, int len)
1585
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
1586
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1588
pci_default_write_config(pci_dev, address, val, len);
1591
!(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER) &&
1592
!(proxy->flags & VIRTIO_PCI_FLAG_BUS_MASTER_BUG)) {
1593
virtio_pci_stop_ioeventfd(proxy);
1594
- virtio_set_status(proxy->vdev,
1595
- proxy->vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK);
1596
+ virtio_set_status(vdev, vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK);
1601
unsigned int vector)
1603
VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
1604
- VirtQueue *vq = virtio_get_queue(proxy->vdev, queue_no);
1605
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1606
+ VirtQueue *vq = virtio_get_queue(vdev, queue_no);
1607
EventNotifier *n = virtio_queue_get_guest_notifier(vq);
1609
ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, NULL, irqfd->virq);
1611
unsigned int queue_no,
1612
unsigned int vector)
1614
- VirtQueue *vq = virtio_get_queue(proxy->vdev, queue_no);
1615
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1616
+ VirtQueue *vq = virtio_get_queue(vdev, queue_no);
1617
EventNotifier *n = virtio_queue_get_guest_notifier(vq);
1618
VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
1621
static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
1623
PCIDevice *dev = &proxy->pci_dev;
1624
- VirtIODevice *vdev = proxy->vdev;
1625
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1626
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
1627
unsigned int vector;
1630
static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
1632
PCIDevice *dev = &proxy->pci_dev;
1633
- VirtIODevice *vdev = proxy->vdev;
1634
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1635
unsigned int vector;
1637
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
1639
unsigned int vector,
1642
- VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(proxy->vdev);
1643
- VirtQueue *vq = virtio_get_queue(proxy->vdev, queue_no);
1644
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1645
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
1646
+ VirtQueue *vq = virtio_get_queue(vdev, queue_no);
1647
EventNotifier *n = virtio_queue_get_guest_notifier(vq);
1650
@@ -626,10 +645,10 @@
1651
* Otherwise, set it up now.
1653
if (k->guest_notifier_mask) {
1654
- k->guest_notifier_mask(proxy->vdev, queue_no, false);
1655
+ k->guest_notifier_mask(vdev, queue_no, false);
1656
/* Test after unmasking to avoid losing events. */
1657
if (k->guest_notifier_pending &&
1658
- k->guest_notifier_pending(proxy->vdev, queue_no)) {
1659
+ k->guest_notifier_pending(vdev, queue_no)) {
1660
event_notifier_set(n);
1663
@@ -642,13 +661,14 @@
1664
unsigned int queue_no,
1665
unsigned int vector)
1667
- VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(proxy->vdev);
1668
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1669
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
1671
/* If guest supports masking, keep irqfd but mask it.
1672
* Otherwise, clean it up now.
1674
if (k->guest_notifier_mask) {
1675
- k->guest_notifier_mask(proxy->vdev, queue_no, true);
1676
+ k->guest_notifier_mask(vdev, queue_no, true);
1678
kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
1683
VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
1684
- VirtIODevice *vdev = proxy->vdev;
1685
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1688
for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) {
1690
static void virtio_pci_vector_mask(PCIDevice *dev, unsigned vector)
1692
VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
1693
- VirtIODevice *vdev = proxy->vdev;
1694
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1697
for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) {
1699
unsigned int vector_end)
1701
VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
1702
- VirtIODevice *vdev = proxy->vdev;
1703
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1704
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
1706
unsigned int vector;
1710
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
1711
- VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(proxy->vdev);
1712
- VirtQueue *vq = virtio_get_queue(proxy->vdev, n);
1713
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1714
+ VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
1715
+ VirtQueue *vq = virtio_get_queue(vdev, n);
1716
EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
1722
if (!msix_enabled(&proxy->pci_dev) && vdc->guest_notifier_mask) {
1723
- vdc->guest_notifier_mask(proxy->vdev, n, !assign);
1724
+ vdc->guest_notifier_mask(vdev, n, !assign);
1729
static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign)
1731
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
1732
- VirtIODevice *vdev = proxy->vdev;
1733
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1734
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
1736
bool with_irqfd = msix_enabled(&proxy->pci_dev) &&
1737
@@ -864,11 +885,12 @@
1738
static void virtio_pci_vmstate_change(DeviceState *d, bool running)
1740
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
1741
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1744
/* Try to find out if the guest has bus master disabled, but is
1745
in ready state. Then we have a buggy guest OS. */
1746
- if ((proxy->vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) &&
1747
+ if ((vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) &&
1748
!(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
1749
proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
1755
- proxy->vdev = bus->vdev;
1757
config = proxy->pci_dev.config;
1758
if (proxy->class_code) {
1759
pci_config_set_class(config, proxy->class_code);
1760
@@ -982,6 +1002,15 @@
1761
proxy->host_features);
1764
+static void virtio_pci_device_unplugged(DeviceState *d)
1766
+ PCIDevice *pci_dev = PCI_DEVICE(d);
1767
+ VirtIOPCIProxy *proxy = VIRTIO_PCI(d);
1769
+ virtio_pci_stop_ioeventfd(proxy);
1770
+ msix_uninit_exclusive_bar(pci_dev);
1773
static int virtio_pci_init(PCIDevice *pci_dev)
1775
VirtIOPCIProxy *dev = VIRTIO_PCI(pci_dev);
1776
@@ -996,9 +1025,7 @@
1777
static void virtio_pci_exit(PCIDevice *pci_dev)
1779
VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
1780
- virtio_pci_stop_ioeventfd(proxy);
1781
memory_region_destroy(&proxy->bar);
1782
- msix_uninit_exclusive_bar(pci_dev);
1785
static void virtio_pci_reset(DeviceState *qdev)
1786
@@ -1533,6 +1560,7 @@
1787
k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
1788
k->vmstate_change = virtio_pci_vmstate_change;
1789
k->device_plugged = virtio_pci_device_plugged;
1790
+ k->device_unplugged = virtio_pci_device_unplugged;
1793
static const TypeInfo virtio_pci_bus_info = {
1794
Index: qemu-1.7.0+dfsg/hw/virtio/virtio-pci.h
1795
===================================================================
1796
--- qemu-1.7.0+dfsg.orig/hw/virtio/virtio-pci.h 2014-01-27 09:09:34.414970261 -0500
1797
+++ qemu-1.7.0+dfsg/hw/virtio/virtio-pci.h 2014-01-27 09:09:34.410970261 -0500
1800
struct VirtIOPCIProxy {
1802
- VirtIODevice *vdev;
1805
uint32_t class_code;
1806
Index: qemu-1.7.0+dfsg/hw/virtio/virtio-rng.c
1807
===================================================================
1808
--- qemu-1.7.0+dfsg.orig/hw/virtio/virtio-rng.c 2014-01-27 09:09:34.414970261 -0500
1809
+++ qemu-1.7.0+dfsg/hw/virtio/virtio-rng.c 2014-01-27 09:09:34.410970261 -0500
1810
@@ -133,27 +133,27 @@
1811
qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + vrng->conf.period_ms);
1814
-static int virtio_rng_device_init(VirtIODevice *vdev)
1815
+static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
1817
- DeviceState *qdev = DEVICE(vdev);
1818
- VirtIORNG *vrng = VIRTIO_RNG(vdev);
1819
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
1820
+ VirtIORNG *vrng = VIRTIO_RNG(dev);
1821
Error *local_err = NULL;
1823
if (!vrng->conf.period_ms > 0) {
1824
- qerror_report(QERR_INVALID_PARAMETER_VALUE, "period",
1825
- "a positive number");
1827
+ error_set(errp, QERR_INVALID_PARAMETER_VALUE, "period",
1828
+ "a positive number");
1832
if (vrng->conf.rng == NULL) {
1833
vrng->conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
1835
- object_property_add_child(OBJECT(qdev),
1836
+ object_property_add_child(OBJECT(dev),
1838
OBJECT(vrng->conf.default_backend),
1841
- object_property_set_link(OBJECT(qdev),
1842
+ object_property_set_link(OBJECT(dev),
1843
OBJECT(vrng->conf.default_backend),
1846
@@ -162,15 +162,14 @@
1848
vrng->rng = vrng->conf.rng;
1849
if (vrng->rng == NULL) {
1850
- qerror_report(QERR_INVALID_PARAMETER_VALUE, "rng", "a valid object");
1852
+ error_set(errp, QERR_INVALID_PARAMETER_VALUE, "rng", "a valid object");
1856
rng_backend_open(vrng->rng, &local_err);
1858
- qerror_report_err(local_err);
1859
- error_free(local_err);
1861
+ error_propagate(errp, local_err);
1865
vrng->vq = virtio_add_queue(vdev, 8, handle_input);
1866
@@ -184,22 +183,19 @@
1867
timer_mod(vrng->rate_limit_timer,
1868
qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + vrng->conf.period_ms);
1870
- register_savevm(qdev, "virtio-rng", -1, 1, virtio_rng_save,
1871
+ register_savevm(dev, "virtio-rng", -1, 1, virtio_rng_save,
1872
virtio_rng_load, vrng);
1877
-static int virtio_rng_device_exit(DeviceState *qdev)
1878
+static void virtio_rng_device_unrealize(DeviceState *dev, Error **errp)
1880
- VirtIORNG *vrng = VIRTIO_RNG(qdev);
1881
- VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
1882
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
1883
+ VirtIORNG *vrng = VIRTIO_RNG(dev);
1885
timer_del(vrng->rate_limit_timer);
1886
timer_free(vrng->rate_limit_timer);
1887
- unregister_savevm(qdev, "virtio-rng", vrng);
1888
+ unregister_savevm(dev, "virtio-rng", vrng);
1889
virtio_cleanup(vdev);
1893
static Property virtio_rng_properties[] = {
1894
@@ -211,10 +207,11 @@
1896
DeviceClass *dc = DEVICE_CLASS(klass);
1897
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
1898
- dc->exit = virtio_rng_device_exit;
1900
dc->props = virtio_rng_properties;
1901
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
1902
- vdc->init = virtio_rng_device_init;
1903
+ vdc->realize = virtio_rng_device_realize;
1904
+ vdc->unrealize = virtio_rng_device_unrealize;
1905
vdc->get_features = get_features;
1908
Index: qemu-1.7.0+dfsg/hw/virtio/virtio.c
1909
===================================================================
1910
--- qemu-1.7.0+dfsg.orig/hw/virtio/virtio.c 2014-01-27 09:09:34.414970261 -0500
1911
+++ qemu-1.7.0+dfsg/hw/virtio/virtio.c 2014-01-27 09:10:06.306971115 -0500
1912
@@ -1150,35 +1150,51 @@
1916
-static int virtio_device_init(DeviceState *qdev)
1917
+static void virtio_device_realize(DeviceState *dev, Error **errp)
1919
- VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
1920
- VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev);
1921
- assert(k->init != NULL);
1922
- if (k->init(vdev) < 0) {
1924
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
1925
+ VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
1926
+ Error *err = NULL;
1928
+ if (vdc->realize != NULL) {
1929
+ vdc->realize(dev, &err);
1930
+ if (err != NULL) {
1931
+ error_propagate(errp, err);
1935
- virtio_bus_plug_device(vdev);
1937
+ virtio_bus_device_plugged(vdev);
1940
-static int virtio_device_exit(DeviceState *qdev)
1941
+static void virtio_device_unrealize(DeviceState *dev, Error **errp)
1943
- VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
1944
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
1945
+ VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
1946
+ Error *err = NULL;
1948
+ virtio_bus_device_unplugged(vdev);
1950
+ if (vdc->unrealize != NULL) {
1951
+ vdc->unrealize(dev, &err);
1952
+ if (err != NULL) {
1953
+ error_propagate(errp, err);
1958
if (vdev->bus_name) {
1959
g_free(vdev->bus_name);
1960
vdev->bus_name = NULL;
1965
static void virtio_device_class_init(ObjectClass *klass, void *data)
1967
/* Set the default value here. */
1968
DeviceClass *dc = DEVICE_CLASS(klass);
1969
- dc->init = virtio_device_init;
1970
- dc->exit = virtio_device_exit;
1972
+ dc->realize = virtio_device_realize;
1973
+ dc->unrealize = virtio_device_unrealize;
1974
dc->bus_type = TYPE_VIRTIO_BUS;
1977
Index: qemu-1.7.0+dfsg/include/hw/virtio/virtio-bus.h
1978
===================================================================
1979
--- qemu-1.7.0+dfsg.orig/include/hw/virtio/virtio-bus.h 2014-01-27 09:09:34.414970261 -0500
1980
+++ qemu-1.7.0+dfsg/include/hw/virtio/virtio-bus.h 2014-01-27 09:09:34.410970261 -0500
1982
* transport independent exit function.
1983
* This is called by virtio-bus just before the device is unplugged.
1985
- void (*device_unplug)(DeviceState *d);
1986
+ void (*device_unplugged)(DeviceState *d);
1988
* Does the transport have variable vring alignment?
1989
* (ie can it ever call virtio_queue_set_align()?)
1992
struct VirtioBusState {
1993
BusState parent_obj;
1995
- * Only one VirtIODevice can be plugged on the bus.
1997
- VirtIODevice *vdev;
2000
-int virtio_bus_plug_device(VirtIODevice *vdev);
2001
+int virtio_bus_device_plugged(VirtIODevice *vdev);
2002
void virtio_bus_reset(VirtioBusState *bus);
2003
-void virtio_bus_destroy_device(VirtioBusState *bus);
2004
+void virtio_bus_device_unplugged(VirtIODevice *bus);
2005
/* Get the device id of the plugged device. */
2006
uint16_t virtio_bus_get_vdev_id(VirtioBusState *bus);
2007
/* Get the config_len field of the plugged device. */
2009
/* Set config of the plugged device. */
2010
void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config);
2012
+static inline VirtIODevice *virtio_bus_get_device(VirtioBusState *bus)
2014
+ BusState *qbus = &bus->parent_obj;
2015
+ BusChild *kid = QTAILQ_FIRST(&qbus->children);
2016
+ DeviceState *qdev = kid ? kid->child : NULL;
2018
+ /* This is used on the data path, the cast is guaranteed
2019
+ * to succeed by the qdev machinery.
2021
+ return (VirtIODevice *)qdev;
2024
#endif /* VIRTIO_BUS_H */
2025
Index: qemu-1.7.0+dfsg/include/hw/virtio/virtio-rng.h
2026
===================================================================
2027
--- qemu-1.7.0+dfsg.orig/include/hw/virtio/virtio-rng.h 2014-01-27 09:09:34.414970261 -0500
2028
+++ qemu-1.7.0+dfsg/include/hw/virtio/virtio-rng.h 2014-01-27 09:09:34.410970261 -0500
2030
#define TYPE_VIRTIO_RNG "virtio-rng-device"
2031
#define VIRTIO_RNG(obj) \
2032
OBJECT_CHECK(VirtIORNG, (obj), TYPE_VIRTIO_RNG)
2033
+#define VIRTIO_RNG_GET_PARENT_CLASS(obj) \
2034
+ OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_RNG)
2036
/* The Virtio ID for the virtio rng device */
2037
#define VIRTIO_ID_RNG 4
2038
Index: qemu-1.7.0+dfsg/include/hw/virtio/virtio-scsi.h
2039
===================================================================
2040
--- qemu-1.7.0+dfsg.orig/include/hw/virtio/virtio-scsi.h 2014-01-27 09:09:34.414970261 -0500
2041
+++ qemu-1.7.0+dfsg/include/hw/virtio/virtio-scsi.h 2014-01-27 09:09:34.410970261 -0500
2043
DEFINE_PROP_BIT("param_change", _state, _feature_field, \
2044
VIRTIO_SCSI_F_CHANGE, true)
2046
-int virtio_scsi_common_init(VirtIOSCSICommon *vs);
2047
-int virtio_scsi_common_exit(VirtIOSCSICommon *vs);
2048
+void virtio_scsi_common_realize(DeviceState *dev, Error **errp);
2049
+void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp);
2051
#endif /* _QEMU_VIRTIO_SCSI_H */
2052
Index: qemu-1.7.0+dfsg/include/hw/virtio/virtio.h
2053
===================================================================
2054
--- qemu-1.7.0+dfsg.orig/include/hw/virtio/virtio.h 2014-01-27 09:09:34.414970261 -0500
2055
+++ qemu-1.7.0+dfsg/include/hw/virtio/virtio.h 2014-01-27 09:09:34.410970261 -0500
2056
@@ -124,9 +124,13 @@
2059
typedef struct VirtioDeviceClass {
2060
- /* This is what a VirtioDevice must implement */
2063
- int (*init)(VirtIODevice *vdev);
2066
+ /* This is what a VirtioDevice must implement */
2067
+ DeviceRealize realize;
2068
+ DeviceUnrealize unrealize;
2069
uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
2070
uint32_t (*bad_features)(VirtIODevice *vdev);
2071
void (*set_features)(VirtIODevice *vdev, uint32_t val);
2072
Index: qemu-1.7.0+dfsg/tests/qdev-monitor-test.c
2073
===================================================================
2074
--- qemu-1.7.0+dfsg.orig/tests/qdev-monitor-test.c 2014-01-27 09:09:34.414970261 -0500
2075
+++ qemu-1.7.0+dfsg/tests/qdev-monitor-test.c 2014-01-27 09:09:34.410970261 -0500
2079
error = qdict_get_qdict(response, "error");
2080
- g_assert(!strcmp(qdict_get_try_str(error, "class") ?: "",
2082
g_assert(!strcmp(qdict_get_try_str(error, "desc") ?: "",
2083
- "Device initialization failed."));
2084
+ "Device needs media, but drive is empty"));
2087
/* Delete the drive */