~ubuntu-branches/ubuntu/vivid/qemu/vivid

« back to all changes in this revision

Viewing changes to debian/patches/ubuntu/CVE-2013-4377.patch

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-02-25 22:31:43 UTC
  • mfrom: (1.8.5)
  • Revision ID: package-import@ubuntu.com-20140225223143-odhqxfc60wxrjl15
Tags: 2.0.0~rc1+dfsg-0ubuntu1
* Merge 2.0.0-rc1
* debian/rules: consolidate ppc filter entries.
* Move qemu-system-arch64 into qemu-system-arm
* debian/patches/define-trusty-machine-type.patch: define a trusty machine
  type, currently the same as pc-i440fx-2.0, to put is in a better position
  to enable live migrations from trusty onward.  (LP: #1294823)
* debian/control: build-dep on libfdt >= 1.4.0  (LP: #1295072)
* Merge latest upstream git to commit dc9528f
* Debian/rules:
  - remove -enable-uname-release=2.6.32
  - don't make the aarch64 target Ubuntu-specific.
* Remove patches which are now upstream:
  - fix-smb-security-share.patch
  - slirp-smb-redirect-port-445-too.patch 
  - linux-user-Implement-sendmmsg-syscall.patch (better version is upstream)
  - signal-added-a-wrapper-for-sigprocmask-function.patch
  - ubuntu/signal-sigsegv-protection-on-do_sigprocmask.patch
  - ubuntu/Don-t-block-SIGSEGV-at-more-places.patch
  - ubuntu/ppc-force-cpu-threads-count-to-be-power-of-2.patch
* add link for /usr/share/qemu/bios-256k.bin
* Remove all linaro patches.
* Remove all arm64/ patches.  Many but not all are upstream.
* Remove CVE-2013-4377.patch which is upstream.
* debian/control-in: don't make qemu-system-aarch64 ubuntu-specific

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
33
 
 
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
38
 
@@ -41,15 +41,16 @@
39
 
     g_free(cfg);
40
 
 }
41
 
 
42
 
-static int virtio_9p_device_init(VirtIODevice *vdev)
43
 
+static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
44
 
 {
45
 
-    V9fsState *s = VIRTIO_9P(vdev);
46
 
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
47
 
+    V9fsState *s = VIRTIO_9P(dev);
48
 
     int i, len;
49
 
     struct stat stat;
50
 
     FsDriverEntry *fse;
51
 
     V9fsPath path;
52
 
 
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);
56
 
 
57
 
     /* initialize pdu allocator */
58
 
@@ -67,16 +68,16 @@
59
 
 
60
 
     if (!fse) {
61
 
         /* We don't have a fsdev identified by fsdev_id */
62
 
-        fprintf(stderr, "Virtio-9p device couldn't find fsdev with the "
63
 
-                "id = %s\n",
64
 
-                s->fsconf.fsdev_id ? s->fsconf.fsdev_id : "NULL");
65
 
+        error_setg(errp, "Virtio-9p device couldn't find fsdev with the "
66
 
+                   "id = %s",
67
 
+                   s->fsconf.fsdev_id ? s->fsconf.fsdev_id : "NULL");
68
 
         goto out;
69
 
     }
70
 
 
71
 
     if (!s->fsconf.tag) {
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);
77
 
         goto out;
78
 
     }
79
 
 
80
 
@@ -85,8 +86,8 @@
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);
88
 
         goto out;
89
 
     }
90
 
 
91
 
@@ -99,12 +100,12 @@
92
 
     qemu_co_rwlock_init(&s->rename_lock);
93
 
 
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);
99
 
         goto out;
100
 
     }
101
 
     if (v9fs_init_worker_threads() < 0) {
102
 
-        fprintf(stderr, "worker thread initialization failed\n");
103
 
+        error_setg(errp, "worker thread initialization failed");
104
 
         goto out;
105
 
     }
106
 
 
107
 
@@ -114,28 +115,25 @@
108
 
      * use co-routines here.
109
 
      */
110
 
     if (s->ops->name_to_path(&s->ctx, NULL, "/", &path) < 0) {
111
 
-        fprintf(stderr,
112
 
-                "error in converting name to path %s", strerror(errno));
113
 
+        error_setg(errp,
114
 
+                   "error in converting name to path %s", strerror(errno));
115
 
         goto out;
116
 
     }
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);
120
 
         goto out;
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);
124
 
         goto out;
125
 
     }
126
 
     v9fs_path_free(&path);
127
 
 
128
 
-    return 0;
129
 
+    return;
130
 
 out:
131
 
     g_free(s->ctx.fs_root);
132
 
     g_free(s->tag);
133
 
     virtio_cleanup(vdev);
134
 
     v9fs_path_free(&path);
135
 
-
136
 
-    return -1;
137
 
-
138
 
 }
139
 
 
140
 
 /* virtio-9p device */
141
 
@@ -149,9 +147,10 @@
142
 
 {
143
 
     DeviceClass *dc = DEVICE_CLASS(klass);
144
 
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
145
 
+
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;
152
 
 }
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
157
 
@@ -380,8 +380,9 @@
158
 
                        s, QEMU_THREAD_JOINABLE);
159
 
 }
160
 
 
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,
165
 
+                                  Error **errp)
166
 
 {
167
 
     VirtIOBlockDataPlane *s;
168
 
     int fd;
169
 
@@ -389,33 +390,35 @@
170
 
     *dataplane = NULL;
171
 
 
172
 
     if (!blk->data_plane) {
173
 
-        return true;
174
 
+        return;
175
 
     }
176
 
 
177
 
     if (blk->scsi) {
178
 
-        error_report("device is incompatible with x-data-plane, use scsi=off");
179
 
-        return false;
180
 
+        error_setg(errp,
181
 
+                   "device is incompatible with x-data-plane, use scsi=off");
182
 
+        return;
183
 
     }
184
 
 
185
 
     if (blk->config_wce) {
186
 
-        error_report("device is incompatible with x-data-plane, "
187
 
-                     "use config-wce=off");
188
 
-        return false;
189
 
+        error_setg(errp, "device is incompatible with x-data-plane, "
190
 
+                         "use config-wce=off");
191
 
+        return;
192
 
     }
193
 
 
194
 
     /* If dataplane is (re-)enabled while the guest is running there could be
195
 
      * block jobs that can conflict.
196
 
      */
197
 
     if (bdrv_in_use(blk->conf.bs)) {
198
 
-        error_report("cannot start dataplane thread while device is in use");
199
 
-        return false;
200
 
+        error_setg(errp,
201
 
+                   "cannot start dataplane thread while device is in use");
202
 
+        return;
203
 
     }
204
 
 
205
 
     fd = raw_get_aio_fd(blk->conf.bs);
206
 
     if (fd < 0) {
207
 
-        error_report("drive is incompatible with x-data-plane, "
208
 
-                     "use format=raw,cache=none,aio=native");
209
 
-        return false;
210
 
+        error_setg(errp, "drive is incompatible with x-data-plane, "
211
 
+                         "use format=raw,cache=none,aio=native");
212
 
+        return;
213
 
     }
214
 
 
215
 
     s = g_new0(VirtIOBlockDataPlane, 1);
216
 
@@ -427,7 +430,6 @@
217
 
     bdrv_set_in_use(blk->conf.bs, 1);
218
 
 
219
 
     *dataplane = s;
220
 
-    return true;
221
 
 }
222
 
 
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
228
 
@@ -19,8 +19,9 @@
229
 
 
230
 
 typedef struct VirtIOBlockDataPlane VirtIOBlockDataPlane;
231
 
 
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,
236
 
+                                  Error **errp);
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
244
 
@@ -657,6 +657,7 @@
245
 
     VirtIOBlock *s = container_of(notifier, VirtIOBlock,
246
 
                                   migration_state_notifier);
247
 
     MigrationState *mig = data;
248
 
+    Error *err = NULL;
249
 
 
250
 
     if (migration_in_setup(mig)) {
251
 
         if (!s->dataplane) {
252
 
@@ -671,31 +672,39 @@
253
 
         }
254
 
         bdrv_drain_all(); /* complete in-flight non-dataplane requests */
255
 
         virtio_blk_data_plane_create(VIRTIO_DEVICE(s), &s->blk,
256
 
-                                     &s->dataplane);
257
 
+                                     &s->dataplane, &err);
258
 
+        if (err != NULL) {
259
 
+            error_report("%s", error_get_pretty(err));
260
 
+            error_free(err);
261
 
+        }
262
 
     }
263
 
 }
264
 
 #endif /* CONFIG_VIRTIO_BLK_DATA_PLANE */
265
 
 
266
 
-static int virtio_blk_device_init(VirtIODevice *vdev)
267
 
+static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
268
 
 {
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
275
 
+    Error *err = NULL;
276
 
+#endif
277
 
     static int virtio_blk_id;
278
 
 
279
 
     if (!blk->conf.bs) {
280
 
-        error_report("drive property not set");
281
 
-        return -1;
282
 
+        error_setg(errp, "drive property not set");
283
 
+        return;
284
 
     }
285
 
     if (!bdrv_is_inserted(blk->conf.bs)) {
286
 
-        error_report("Device needs media, but drive is empty");
287
 
-        return -1;
288
 
+        error_setg(errp, "Device needs media, but drive is empty");
289
 
+        return;
290
 
     }
291
 
 
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) {
295
 
-        return -1;
296
 
+        error_setg(errp, "Error setting geometry");
297
 
+        return;
298
 
     }
299
 
 
300
 
     virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
301
 
@@ -708,30 +717,32 @@
302
 
 
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);
307
 
+    if (err != NULL) {
308
 
+        error_propagate(errp, err);
309
 
         virtio_cleanup(vdev);
310
 
-        return -1;
311
 
+        return;
312
 
     }
313
 
     s->migration_state_notifier.notify = virtio_blk_migration_state_changed;
314
 
     add_migration_state_change_notifier(&s->migration_state_notifier);
315
 
 #endif
316
 
 
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);
323
 
 
324
 
     bdrv_iostatus_enable(s->bs);
325
 
 
326
 
-    add_boot_device_path(s->conf->bootindex, qdev, "/disk@0,0");
327
 
-    return 0;
328
 
+    add_boot_device_path(s->conf->bootindex, dev, "/disk@0,0");
329
 
 }
330
 
 
331
 
-static int virtio_blk_device_exit(DeviceState *dev)
332
 
+static void virtio_blk_device_unrealize(DeviceState *dev, Error **errp)
333
 
 {
334
 
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
335
 
     VirtIOBlock *s = VIRTIO_BLK(dev);
336
 
+
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);
340
 
@@ -741,7 +752,6 @@
341
 
     unregister_savevm(dev, "virtio-blk", s);
342
 
     blockdev_mark_auto_del(s->bs);
343
 
     virtio_cleanup(vdev);
344
 
-    return 0;
345
 
 }
346
 
 
347
 
 static Property virtio_blk_properties[] = {
348
 
@@ -753,10 +763,11 @@
349
 
 {
350
 
     DeviceClass *dc = DEVICE_CLASS(klass);
351
 
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
352
 
-    dc->exit = virtio_blk_device_exit;
353
 
+
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 @@
367
 
     return 0;
368
 
 }
369
 
 
370
 
-static int virtio_serial_device_init(VirtIODevice *vdev)
371
 
+static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
372
 
 {
373
 
-    DeviceState *qdev = DEVICE(vdev);
374
 
-    VirtIOSerial *vser = VIRTIO_SERIAL(vdev);
375
 
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
376
 
+    VirtIOSerial *vser = VIRTIO_SERIAL(dev);
377
 
+    BusState *bus;
378
 
     uint32_t i, max_supported_ports;
379
 
 
380
 
     if (!vser->serial.max_virtserial_ports) {
381
 
-        return -1;
382
 
+        error_setg(errp, "Maximum number of serial ports not specified");
383
 
+        return;
384
 
     }
385
 
 
386
 
     /* Each port takes 2 queues, and one pair is for the control queue */
387
 
     max_supported_ports = VIRTIO_PCI_QUEUE_MAX / 2 - 1;
388
 
 
389
 
     if (vser->serial.max_virtserial_ports > max_supported_ports) {
390
 
-        error_report("maximum ports supported: %u", max_supported_ports);
391
 
-        return -1;
392
 
+        error_setg(errp, "maximum ports supported: %u", max_supported_ports);
393
 
+        return;
394
 
     }
395
 
 
396
 
     virtio_init(vdev, "virtio-serial", VIRTIO_ID_CONSOLE,
397
 
@@ -912,8 +914,9 @@
398
 
 
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);
408
 
 
409
 
@@ -961,10 +964,8 @@
410
 
      * Register for the savevm section with the virtio-console name
411
 
      * to preserve backward compat
412
 
      */
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);
416
 
-
417
 
-    return 0;
418
 
 }
419
 
 
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,
423
 
 };
424
 
 
425
 
-static int virtio_serial_device_exit(DeviceState *dev)
426
 
+static void virtio_serial_device_unrealize(DeviceState *dev, Error **errp)
427
 
 {
428
 
-    VirtIOSerial *vser = VIRTIO_SERIAL(dev);
429
 
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
430
 
+    VirtIOSerial *vser = VIRTIO_SERIAL(dev);
431
 
 
432
 
     unregister_savevm(dev, "virtio-console", vser);
433
 
 
434
 
@@ -1004,7 +1005,6 @@
435
 
         g_free(vser->post_load);
436
 
     }
437
 
     virtio_cleanup(vdev);
438
 
-    return 0;
439
 
 }
440
 
 
441
 
 static Property virtio_serial_properties[] = {
442
 
@@ -1016,10 +1016,11 @@
443
 
 {
444
 
     DeviceClass *dc = DEVICE_CLASS(klass);
445
 
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
446
 
-    dc->exit = virtio_serial_device_exit;
447
 
+
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);
462
 
 }
463
 
 
464
 
-static int virtio_net_device_init(VirtIODevice *vdev)
465
 
+static void virtio_net_device_realize(DeviceState *dev, Error **errp)
466
 
 {
467
 
-    int i;
468
 
-
469
 
-    DeviceState *qdev = DEVICE(vdev);
470
 
-    VirtIONet *n = VIRTIO_NET(vdev);
471
 
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
472
 
+    VirtIONet *n = VIRTIO_NET(dev);
473
 
     NetClientState *nc;
474
 
+    int i;
475
 
 
476
 
-    virtio_init(VIRTIO_DEVICE(n), "virtio-net", VIRTIO_ID_NET,
477
 
-                                  n->config_size);
478
 
+    virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size);
479
 
 
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);
484
 
     } else {
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);
488
 
     }
489
 
 
490
 
     peer_test_vnet_hdr(n);
491
 
@@ -1562,24 +1560,23 @@
492
 
     nc = qemu_get_queue(n->nic);
493
 
     nc->rxfilter_notify_enabled = 1;
494
 
 
495
 
-    n->qdev = qdev;
496
 
-    register_savevm(qdev, "virtio-net", -1, VIRTIO_NET_VM_VERSION,
497
 
+    n->qdev = dev;
498
 
+    register_savevm(dev, "virtio-net", -1, VIRTIO_NET_VM_VERSION,
499
 
                     virtio_net_save, virtio_net_load, n);
500
 
 
501
 
-    add_boot_device_path(n->nic_conf.bootindex, qdev, "/ethernet-phy@0");
502
 
-    return 0;
503
 
+    add_boot_device_path(n->nic_conf.bootindex, dev, "/ethernet-phy@0");
504
 
 }
505
 
 
506
 
-static int virtio_net_device_exit(DeviceState *qdev)
507
 
+static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
508
 
 {
509
 
-    VirtIONet *n = VIRTIO_NET(qdev);
510
 
-    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
511
 
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
512
 
+    VirtIONet *n = VIRTIO_NET(dev);
513
 
     int i;
514
 
 
515
 
     /* This will stop vhost backend if appropriate. */
516
 
     virtio_net_set_status(vdev, 0);
517
 
 
518
 
-    unregister_savevm(qdev, "virtio-net", n);
519
 
+    unregister_savevm(dev, "virtio-net", n);
520
 
 
521
 
     if (n->netclient_name) {
522
 
         g_free(n->netclient_name);
523
 
@@ -1610,8 +1607,6 @@
524
 
     g_free(n->vqs);
525
 
     qemu_del_nic(n->nic);
526
 
     virtio_cleanup(vdev);
527
 
-
528
 
-    return 0;
529
 
 }
530
 
 
531
 
 static void virtio_net_instance_init(Object *obj)
532
 
@@ -1638,10 +1633,11 @@
533
 
 {
534
 
     DeviceClass *dc = DEVICE_CLASS(klass);
535
 
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
536
 
-    dc->exit = virtio_net_device_exit;
537
 
+
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
550
 
@@ -57,9 +57,10 @@
551
 
 VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
552
 
 {
553
 
     VirtIODevice *vdev = NULL;
554
 
+    VirtioCcwDevice *dev = sch->driver_data;
555
 
 
556
 
-    if (sch->driver_data) {
557
 
-        vdev = ((VirtioCcwDevice *)sch->driver_data)->vdev;
558
 
+    if (dev) {
559
 
+        vdev = virtio_bus_get_device(&dev->bus);
560
 
     }
561
 
     return vdev;
562
 
 }
563
 
@@ -67,7 +68,8 @@
564
 
 static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,
565
 
                                               bool assign, bool set_handler)
566
 
 {
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);
571
 
     int r = 0;
572
 
     SubchDev *sch = dev->sch;
573
 
@@ -97,6 +99,7 @@
574
 
 
575
 
 static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
576
 
 {
577
 
+    VirtIODevice *vdev;
578
 
     int n, r;
579
 
 
580
 
     if (!(dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) ||
581
 
@@ -104,8 +107,9 @@
582
 
         dev->ioeventfd_started) {
583
 
         return;
584
 
     }
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)) {
589
 
             continue;
590
 
         }
591
 
         r = virtio_ccw_set_guest2host_notifier(dev, n, true, true);
592
 
@@ -118,7 +122,7 @@
593
 
 
594
 
   assign_error:
595
 
     while (--n >= 0) {
596
 
-        if (!virtio_queue_get_num(dev->vdev, n)) {
597
 
+        if (!virtio_queue_get_num(vdev, n)) {
598
 
             continue;
599
 
         }
600
 
         r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
601
 
@@ -132,13 +136,15 @@
602
 
 
603
 
 static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev)
604
 
 {
605
 
+    VirtIODevice *vdev;
606
 
     int n, r;
607
 
 
608
 
     if (!dev->ioeventfd_started) {
609
 
         return;
610
 
     }
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)) {
615
 
             continue;
616
 
         }
617
 
         r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
618
 
@@ -189,7 +195,7 @@
619
 
 static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,
620
 
                               uint16_t index, uint16_t num)
621
 
 {
622
 
-    VirtioCcwDevice *dev = sch->driver_data;
623
 
+    VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
624
 
 
625
 
     if (index > VIRTIO_PCI_QUEUE_MAX) {
626
 
         return -EINVAL;
627
 
@@ -200,23 +206,23 @@
628
 
         return -EINVAL;
629
 
     }
630
 
 
631
 
-    if (!dev) {
632
 
+    if (!vdev) {
633
 
         return -EINVAL;
634
 
     }
635
 
 
636
 
-    virtio_queue_set_addr(dev->vdev, index, addr);
637
 
+    virtio_queue_set_addr(vdev, index, addr);
638
 
     if (!addr) {
639
 
-        virtio_queue_set_vector(dev->vdev, index, 0);
640
 
+        virtio_queue_set_vector(vdev, index, 0);
641
 
     } else {
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) {
646
 
             return -EINVAL;
647
 
         }
648
 
-        virtio_queue_set_vector(dev->vdev, index, index);
649
 
+        virtio_queue_set_vector(vdev, index, index);
650
 
     }
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;
654
 
     return 0;
655
 
 }
656
 
 
657
 
@@ -230,6 +236,7 @@
658
 
     hwaddr indicators;
659
 
     VqConfigBlock vq_config;
660
 
     VirtioCcwDevice *dev = sch->driver_data;
661
 
+    VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
662
 
     bool check_len;
663
 
     int len;
664
 
     hwaddr hw_len;
665
 
@@ -272,7 +279,7 @@
666
 
         break;
667
 
     case CCW_CMD_VDEV_RESET:
668
 
         virtio_ccw_stop_ioeventfd(dev);
669
 
-        virtio_reset(dev->vdev);
670
 
+        virtio_reset(vdev);
671
 
         ret = 0;
672
 
         break;
673
 
     case CCW_CMD_READ_FEAT:
674
 
@@ -319,7 +326,7 @@
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;
680
 
             } else {
681
 
                 /*
682
 
                  * If the guest supports more feature bits, assert that it
683
 
@@ -337,30 +344,30 @@
684
 
         break;
685
 
     case CCW_CMD_READ_CONF:
686
 
         if (check_len) {
687
 
-            if (ccw.count > dev->vdev->config_len) {
688
 
+            if (ccw.count > vdev->config_len) {
689
 
                 ret = -EINVAL;
690
 
                 break;
691
 
             }
692
 
         }
693
 
-        len = MIN(ccw.count, dev->vdev->config_len);
694
 
+        len = MIN(ccw.count, vdev->config_len);
695
 
         if (!ccw.cda) {
696
 
             ret = -EFAULT;
697
 
         } else {
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;
704
 
             ret = 0;
705
 
         }
706
 
         break;
707
 
     case CCW_CMD_WRITE_CONF:
708
 
         if (check_len) {
709
 
-            if (ccw.count > dev->vdev->config_len) {
710
 
+            if (ccw.count > vdev->config_len) {
711
 
                 ret = -EINVAL;
712
 
                 break;
713
 
             }
714
 
         }
715
 
-        len = MIN(ccw.count, dev->vdev->config_len);
716
 
+        len = MIN(ccw.count, vdev->config_len);
717
 
         hw_len = len;
718
 
         if (!ccw.cda) {
719
 
             ret = -EFAULT;
720
 
@@ -371,9 +378,9 @@
721
 
             } else {
722
 
                 len = hw_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;
730
 
                 ret = 0;
731
 
             }
732
 
@@ -397,9 +404,9 @@
733
 
             if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
734
 
                 virtio_ccw_stop_ioeventfd(dev);
735
 
             }
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);
742
 
             }
743
 
             if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
744
 
                 virtio_ccw_start_ioeventfd(dev);
745
 
@@ -463,7 +470,7 @@
746
 
             ret = -EFAULT;
747
 
         } else {
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,
751
 
                                                      vq_config.index);
752
 
             stw_phys(ccw.cda + sizeof(vq_config.index), vq_config.num_max);
753
 
             sch->curr_status.scsw.count = ccw.count - sizeof(vq_config);
754
 
@@ -495,7 +502,6 @@
755
 
     sch->driver_data = dev;
756
 
     dev->sch = sch;
757
 
 
758
 
-    dev->vdev = vdev;
759
 
     dev->indicators = 0;
760
 
 
761
 
     /* Initialize subchannel structure. */
762
 
@@ -608,7 +614,7 @@
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;
768
 
 
769
 
     /* Only the first 32 feature bits are used. */
770
 
     dev->host_features[0] = virtio_bus_get_vdev_features(&dev->bus,
771
 
@@ -631,7 +637,6 @@
772
 
 {
773
 
     SubchDev *sch = dev->sch;
774
 
 
775
 
-    virtio_ccw_stop_ioeventfd(dev);
776
 
     if (sch) {
777
 
         css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
778
 
         g_free(sch);
779
 
@@ -892,9 +897,10 @@
780
 
 static void virtio_ccw_reset(DeviceState *d)
781
 
 {
782
 
     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
783
 
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
784
 
 
785
 
     virtio_ccw_stop_ioeventfd(dev);
786
 
-    virtio_reset(dev->vdev);
787
 
+    virtio_reset(vdev);
788
 
     css_reset_sch(dev->sch);
789
 
     dev->indicators = 0;
790
 
     dev->indicators2 = 0;
791
 
@@ -934,9 +940,10 @@
792
 
 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
793
 
                                          bool assign, bool with_irqfd)
794
 
 {
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);
801
 
 
802
 
     if (assign) {
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.
806
 
          */
807
 
         if (k->guest_notifier_mask) {
808
 
-            k->guest_notifier_mask(dev->vdev, n, false);
809
 
+            k->guest_notifier_mask(vdev, n, false);
810
 
         }
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);
816
 
         }
817
 
     } else {
818
 
         if (k->guest_notifier_mask) {
819
 
-            k->guest_notifier_mask(dev->vdev, n, true);
820
 
+            k->guest_notifier_mask(vdev, n, true);
821
 
         }
822
 
         virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
823
 
         event_notifier_cleanup(notifier);
824
 
@@ -973,7 +980,7 @@
825
 
                                           bool assigned)
826
 
 {
827
 
     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
828
 
-    VirtIODevice *vdev = dev->vdev;
829
 
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
830
 
     int r, n;
831
 
 
832
 
     for (n = 0; n < nvqs; n++) {
833
 
@@ -1228,6 +1235,8 @@
834
 
     VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
835
 
     SubchDev *sch = _dev->sch;
836
 
 
837
 
+    virtio_ccw_stop_ioeventfd(_dev);
838
 
+
839
 
     /*
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
846
 
@@ -77,7 +77,6 @@
847
 
 struct VirtioCcwDevice {
848
 
     DeviceState parent_obj;
849
 
     SubchDev *sch;
850
 
-    VirtIODevice *vdev;
851
 
     char *bus_id;
852
 
     uint32_t host_features[VIRTIO_CCW_FEATURE_SIZE];
853
 
     VirtioBusState bus;
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 @@
859
 
     }
860
 
 }
861
 
 
862
 
-static int vhost_scsi_init(VirtIODevice *vdev)
863
 
+static void vhost_scsi_realize(DeviceState *dev, Error **errp)
864
 
 {
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);
869
 
+    Error *err = NULL;
870
 
     int vhostfd = -1;
871
 
     int ret;
872
 
 
873
 
     if (!vs->conf.wwpn) {
874
 
-        error_report("vhost-scsi: missing wwpn\n");
875
 
-        return -EINVAL;
876
 
+        error_setg(errp, "vhost-scsi: missing wwpn");
877
 
+        return;
878
 
     }
879
 
 
880
 
     if (vs->conf.vhostfd) {
881
 
         vhostfd = monitor_handle_fd_param(cur_mon, vs->conf.vhostfd);
882
 
         if (vhostfd == -1) {
883
 
-            error_report("vhost-scsi: unable to parse vhostfd\n");
884
 
-            return -EINVAL;
885
 
+            error_setg(errp, "vhost-scsi: unable to parse vhostfd");
886
 
+            return;
887
 
         }
888
 
     }
889
 
 
890
 
-    ret = virtio_scsi_common_init(vs);
891
 
-    if (ret < 0) {
892
 
-        return ret;
893
 
+    virtio_scsi_common_realize(dev, &err);
894
 
+    if (err != NULL) {
895
 
+        error_propagate(errp, err);
896
 
+        return;
897
 
     }
898
 
 
899
 
     s->dev.nvqs = VHOST_SCSI_VQ_NUM_FIXED + vs->conf.num_queues;
900
 
@@ -227,24 +229,21 @@
901
 
 
902
 
     ret = vhost_dev_init(&s->dev, vhostfd, "/dev/vhost-scsi", true);
903
 
     if (ret < 0) {
904
 
-        error_report("vhost-scsi: vhost initialization failed: %s\n",
905
 
-                strerror(-ret));
906
 
-        return ret;
907
 
+        error_setg(errp, "vhost-scsi: vhost initialization failed: %s",
908
 
+                   strerror(-ret));
909
 
+        return;
910
 
     }
911
 
     s->dev.backend_features = 0;
912
 
 
913
 
     error_setg(&s->migration_blocker,
914
 
             "vhost-scsi does not support migration");
915
 
     migrate_add_blocker(s->migration_blocker);
916
 
-
917
 
-    return 0;
918
 
 }
919
 
 
920
 
-static int vhost_scsi_exit(DeviceState *qdev)
921
 
+static void vhost_scsi_unrealize(DeviceState *dev, Error **errp)
922
 
 {
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);
928
 
 
929
 
     migrate_del_blocker(s->migration_blocker);
930
 
     error_free(s->migration_blocker);
931
 
@@ -253,7 +252,8 @@
932
 
     vhost_scsi_set_status(vdev, 0);
933
 
 
934
 
     g_free(s->dev.vqs);
935
 
-    return virtio_scsi_common_exit(vs);
936
 
+
937
 
+    virtio_scsi_common_unrealize(dev, errp);
938
 
 }
939
 
 
940
 
 static Property vhost_scsi_properties[] = {
941
 
@@ -265,10 +265,11 @@
942
 
 {
943
 
     DeviceClass *dc = DEVICE_CLASS(klass);
944
 
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
945
 
-    dc->exit = vhost_scsi_exit;
946
 
+
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,
961
 
 };
962
 
 
963
 
-int virtio_scsi_common_init(VirtIOSCSICommon *s)
964
 
+void virtio_scsi_common_realize(DeviceState *dev, Error **errp)
965
 
 {
966
 
-    VirtIODevice *vdev = VIRTIO_DEVICE(s);
967
 
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
968
 
+    VirtIOSCSICommon *s = VIRTIO_SCSI_COMMON(dev);
969
 
     int i;
970
 
 
971
 
-    virtio_init(VIRTIO_DEVICE(s), "virtio-scsi", VIRTIO_ID_SCSI,
972
 
+    virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI,
973
 
                 sizeof(VirtIOSCSIConfig));
974
 
 
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);
979
 
     }
980
 
-
981
 
-    return 0;
982
 
 }
983
 
 
984
 
-static int virtio_scsi_device_init(VirtIODevice *vdev)
985
 
+static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
986
 
 {
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;
993
 
     Error *err = NULL;
994
 
-    int ret;
995
 
 
996
 
-    ret = virtio_scsi_common_init(vs);
997
 
-    if (ret < 0) {
998
 
-        return ret;
999
 
+    virtio_scsi_common_realize(dev, &err);
1000
 
+    if (err != NULL) {
1001
 
+        error_propagate(errp, err);
1002
 
+        return;
1003
 
     }
1004
 
 
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);
1008
 
 
1009
 
-    if (!qdev->hotplugged) {
1010
 
+    if (!dev->hotplugged) {
1011
 
         scsi_bus_legacy_handle_cmdline(&s->bus, &err);
1012
 
         if (err != NULL) {
1013
 
-            error_free(err);
1014
 
-            return -1;
1015
 
+            error_propagate(errp, err);
1016
 
+            return;
1017
 
         }
1018
 
     }
1019
 
 
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);
1023
 
-
1024
 
-    return 0;
1025
 
 }
1026
 
 
1027
 
-int virtio_scsi_common_exit(VirtIOSCSICommon *vs)
1028
 
+void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp)
1029
 
 {
1030
 
-    VirtIODevice *vdev = VIRTIO_DEVICE(vs);
1031
 
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
1032
 
+    VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
1033
 
 
1034
 
     g_free(vs->cmd_vqs);
1035
 
     virtio_cleanup(vdev);
1036
 
-    return 0;
1037
 
 }
1038
 
 
1039
 
-static int virtio_scsi_device_exit(DeviceState *qdev)
1040
 
+static void virtio_scsi_device_unrealize(DeviceState *dev, Error **errp)
1041
 
 {
1042
 
-    VirtIOSCSI *s = VIRTIO_SCSI(qdev);
1043
 
-    VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(qdev);
1044
 
+    VirtIOSCSI *s = VIRTIO_SCSI(dev);
1045
 
 
1046
 
-    unregister_savevm(qdev, "virtio-scsi", s);
1047
 
-    return virtio_scsi_common_exit(vs);
1048
 
+    unregister_savevm(dev, "virtio-scsi", s);
1049
 
+
1050
 
+    virtio_scsi_common_unrealize(dev, errp);
1051
 
 }
1052
 
 
1053
 
 static Property virtio_scsi_properties[] = {
1054
 
@@ -680,10 +676,11 @@
1055
 
 {
1056
 
     DeviceClass *dc = DEVICE_CLASS(klass);
1057
 
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
1058
 
-    dc->exit = virtio_scsi_device_exit;
1059
 
+
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 @@
1073
 
     return 0;
1074
 
 }
1075
 
 
1076
 
-static int virtio_balloon_device_init(VirtIODevice *vdev)
1077
 
+static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
1078
 
 {
1079
 
-    DeviceState *qdev = DEVICE(vdev);
1080
 
-    VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
1081
 
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
1082
 
+    VirtIOBalloon *s = VIRTIO_BALLOON(dev);
1083
 
     int ret;
1084
 
 
1085
 
     virtio_init(vdev, "virtio-balloon", VIRTIO_ID_BALLOON, 8);
1086
 
@@ -349,37 +349,36 @@
1087
 
                                    virtio_balloon_stat, s);
1088
 
 
1089
 
     if (ret < 0) {
1090
 
-        virtio_cleanup(VIRTIO_DEVICE(s));
1091
 
-        return -1;
1092
 
+        error_setg(errp, "Adding balloon handler failed");
1093
 
+        virtio_cleanup(vdev);
1094
 
+        return;
1095
 
     }
1096
 
 
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);
1100
 
 
1101
 
-    register_savevm(qdev, "virtio-balloon", -1, 1,
1102
 
+    register_savevm(dev, "virtio-balloon", -1, 1,
1103
 
                     virtio_balloon_save, virtio_balloon_load, s);
1104
 
 
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);
1108
 
 
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,
1113
 
                         NULL, s, NULL);
1114
 
-    return 0;
1115
 
 }
1116
 
 
1117
 
-static int virtio_balloon_device_exit(DeviceState *qdev)
1118
 
+static void virtio_balloon_device_unrealize(DeviceState *dev, Error **errp)
1119
 
 {
1120
 
-    VirtIOBalloon *s = VIRTIO_BALLOON(qdev);
1121
 
-    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
1122
 
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
1123
 
+    VirtIOBalloon *s = VIRTIO_BALLOON(dev);
1124
 
 
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);
1130
 
-    return 0;
1131
 
 }
1132
 
 
1133
 
 static Property virtio_balloon_properties[] = {
1134
 
@@ -390,10 +389,11 @@
1135
 
 {
1136
 
     DeviceClass *dc = DEVICE_CLASS(klass);
1137
 
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
1138
 
-    dc->exit = virtio_balloon_device_exit;
1139
 
+
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
1152
 
@@ -37,8 +37,8 @@
1153
 
 #define DPRINTF(fmt, ...) do { } while (0)
1154
 
 #endif
1155
 
 
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)
1160
 
 {
1161
 
     DeviceState *qdev = DEVICE(vdev);
1162
 
     BusState *qbus = BUS(qdev_get_parent_bus(qdev));
1163
 
@@ -46,8 +46,6 @@
1164
 
     VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
1165
 
     DPRINTF("%s: plug device.\n", qbus->name);
1166
 
 
1167
 
-    bus->vdev = vdev;
1168
 
-
1169
 
     if (klass->device_plugged != NULL) {
1170
 
         klass->device_plugged(qbus->parent);
1171
 
     }
1172
 
@@ -58,73 +56,83 @@
1173
 
 /* Reset the virtio_bus */
1174
 
 void virtio_bus_reset(VirtioBusState *bus)
1175
 
 {
1176
 
+    VirtIODevice *vdev = virtio_bus_get_device(bus);
1177
 
+
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);
1183
 
     }
1184
 
 }
1185
 
 
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)
1190
 
 {
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);
1196
 
+
1197
 
     DPRINTF("%s: remove device.\n", qbus->name);
1198
 
 
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);
1205
 
         }
1206
 
-        object_unparent(OBJECT(bus->vdev));
1207
 
-        bus->vdev = NULL;
1208
 
     }
1209
 
 }
1210
 
 
1211
 
 /* Get the device id of the plugged device. */
1212
 
 uint16_t virtio_bus_get_vdev_id(VirtioBusState *bus)
1213
 
 {
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;
1219
 
 }
1220
 
 
1221
 
 /* Get the config_len field of the plugged device. */
1222
 
 size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus)
1223
 
 {
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;
1229
 
 }
1230
 
 
1231
 
 /* Get the features of the plugged device. */
1232
 
 uint32_t virtio_bus_get_vdev_features(VirtioBusState *bus,
1233
 
                                     uint32_t requested_features)
1234
 
 {
1235
 
+    VirtIODevice *vdev = virtio_bus_get_device(bus);
1236
 
     VirtioDeviceClass *k;
1237
 
-    assert(bus->vdev != NULL);
1238
 
-    k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
1239
 
+
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);
1245
 
 }
1246
 
 
1247
 
 /* Set the features of the plugged device. */
1248
 
 void virtio_bus_set_vdev_features(VirtioBusState *bus,
1249
 
                                       uint32_t requested_features)
1250
 
 {
1251
 
+    VirtIODevice *vdev = virtio_bus_get_device(bus);
1252
 
     VirtioDeviceClass *k;
1253
 
-    assert(bus->vdev != NULL);
1254
 
-    k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
1255
 
+
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);
1261
 
     }
1262
 
 }
1263
 
 
1264
 
 /* Get bad features of the plugged device. */
1265
 
 uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus)
1266
 
 {
1267
 
+    VirtIODevice *vdev = virtio_bus_get_device(bus);
1268
 
     VirtioDeviceClass *k;
1269
 
-    assert(bus->vdev != NULL);
1270
 
-    k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
1271
 
+
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);
1277
 
     } else {
1278
 
         return 0;
1279
 
     }
1280
 
@@ -133,22 +141,26 @@
1281
 
 /* Get config of the plugged device. */
1282
 
 void virtio_bus_get_vdev_config(VirtioBusState *bus, uint8_t *config)
1283
 
 {
1284
 
+    VirtIODevice *vdev = virtio_bus_get_device(bus);
1285
 
     VirtioDeviceClass *k;
1286
 
-    assert(bus->vdev != NULL);
1287
 
-    k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
1288
 
+
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);
1294
 
     }
1295
 
 }
1296
 
 
1297
 
 /* Set config of the plugged device. */
1298
 
 void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config)
1299
 
 {
1300
 
+    VirtIODevice *vdev = virtio_bus_get_device(bus);
1301
 
     VirtioDeviceClass *k;
1302
 
-    assert(bus->vdev != NULL);
1303
 
-    k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
1304
 
+
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);
1310
 
     }
1311
 
 }
1312
 
 
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
1317
 
@@ -95,7 +95,7 @@
1318
 
 static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size)
1319
 
 {
1320
 
     VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque;
1321
 
-    VirtIODevice *vdev = proxy->bus.vdev;
1322
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1323
 
 
1324
 
     DPRINTF("virtio_mmio_read offset 0x%x\n", (int)offset);
1325
 
 
1326
 
@@ -185,7 +185,7 @@
1327
 
                               unsigned size)
1328
 
 {
1329
 
     VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque;
1330
 
-    VirtIODevice *vdev = proxy->bus.vdev;
1331
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1332
 
 
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)
1337
 
 {
1338
 
     VirtIOMMIOProxy *proxy = VIRTIO_MMIO(opaque);
1339
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1340
 
     int level;
1341
 
 
1342
 
-    if (!proxy->bus.vdev) {
1343
 
+    if (!vdev) {
1344
 
         return;
1345
 
     }
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);
1350
 
 }
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)
1357
 
 {
1358
 
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy_fast(d);
1359
 
+
1360
 
     if (msix_enabled(&proxy->pci_dev))
1361
 
         msix_notify(&proxy->pci_dev, vector);
1362
 
-    else
1363
 
-        pci_set_irq(&proxy->pci_dev, proxy->vdev->isr & 1);
1364
 
+    else {
1365
 
+        VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1366
 
+        pci_set_irq(&proxy->pci_dev, vdev->isr & 1);
1367
 
+    }
1368
 
 }
1369
 
 
1370
 
 static void virtio_pci_save_config(DeviceState *d, QEMUFile *f)
1371
 
 {
1372
 
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
1373
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1374
 
+
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);
1380
 
 }
1381
 
 
1382
 
 static void virtio_pci_save_queue(DeviceState *d, int n, QEMUFile *f)
1383
 
 {
1384
 
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
1385
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1386
 
+
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));
1390
 
 }
1391
 
 
1392
 
 static int virtio_pci_load_config(DeviceState *d, QEMUFile *f)
1393
 
 {
1394
 
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
1395
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1396
 
+
1397
 
     int ret;
1398
 
     ret = pci_device_load(&proxy->pci_dev, f);
1399
 
     if (ret) {
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);
1406
 
     } else {
1407
 
-        proxy->vdev->config_vector = VIRTIO_NO_VECTOR;
1408
 
+        vdev->config_vector = VIRTIO_NO_VECTOR;
1409
 
     }
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);
1414
 
     }
1415
 
     return 0;
1416
 
 }
1417
 
@@ -159,13 +168,15 @@
1418
 
 static int virtio_pci_load_queue(DeviceState *d, int n, QEMUFile *f)
1419
 
 {
1420
 
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
1421
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1422
 
+
1423
 
     uint16_t vector;
1424
 
     if (msix_present(&proxy->pci_dev)) {
1425
 
         qemu_get_be16s(f, &vector);
1426
 
     } else {
1427
 
         vector = VIRTIO_NO_VECTOR;
1428
 
     }
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);
1433
 
     }
1434
 
@@ -175,7 +186,8 @@
1435
 
 static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
1436
 
                                                  int n, bool assign, bool set_handler)
1437
 
 {
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);
1442
 
     int r = 0;
1443
 
 
1444
 
@@ -200,6 +212,7 @@
1445
 
 
1446
 
 static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy)
1447
 
 {
1448
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1449
 
     int n, r;
1450
 
 
1451
 
     if (!(proxy->flags & VIRTIO_PCI_FLAG_USE_IOEVENTFD) ||
1452
 
@@ -209,7 +222,7 @@
1453
 
     }
1454
 
 
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)) {
1458
 
             continue;
1459
 
         }
1460
 
 
1461
 
@@ -223,7 +236,7 @@
1462
 
 
1463
 
 assign_error:
1464
 
     while (--n >= 0) {
1465
 
-        if (!virtio_queue_get_num(proxy->vdev, n)) {
1466
 
+        if (!virtio_queue_get_num(vdev, n)) {
1467
 
             continue;
1468
 
         }
1469
 
 
1470
 
@@ -236,6 +249,7 @@
1471
 
 
1472
 
 static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
1473
 
 {
1474
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1475
 
     int r;
1476
 
     int n;
1477
 
 
1478
 
@@ -244,7 +258,7 @@
1479
 
     }
1480
 
 
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)) {
1484
 
             continue;
1485
 
         }
1486
 
 
1487
 
@@ -257,7 +271,7 @@
1488
 
 static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
1489
 
 {
1490
 
     VirtIOPCIProxy *proxy = opaque;
1491
 
-    VirtIODevice *vdev = proxy->vdev;
1492
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1493
 
     hwaddr pa;
1494
 
 
1495
 
     switch (addr) {
1496
 
@@ -272,7 +286,7 @@
1497
 
         pa = (hwaddr)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT;
1498
 
         if (pa == 0) {
1499
 
             virtio_pci_stop_ioeventfd(proxy);
1500
 
-            virtio_reset(proxy->vdev);
1501
 
+            virtio_reset(vdev);
1502
 
             msix_unuse_all_vectors(&proxy->pci_dev);
1503
 
         }
1504
 
         else
1505
 
@@ -299,7 +313,7 @@
1506
 
         }
1507
 
 
1508
 
         if (vdev->status == 0) {
1509
 
-            virtio_reset(proxy->vdev);
1510
 
+            virtio_reset(vdev);
1511
 
             msix_unuse_all_vectors(&proxy->pci_dev);
1512
 
         }
1513
 
 
1514
 
@@ -335,7 +349,7 @@
1515
 
 
1516
 
 static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr)
1517
 
 {
1518
 
-    VirtIODevice *vdev = proxy->vdev;
1519
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1520
 
     uint32_t ret = 0xFFFFFFFF;
1521
 
 
1522
 
     switch (addr) {
1523
 
@@ -381,6 +395,7 @@
1524
 
                                        unsigned size)
1525
 
 {
1526
 
     VirtIOPCIProxy *proxy = opaque;
1527
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1528
 
     uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
1529
 
     uint64_t val = 0;
1530
 
     if (addr < config) {
1531
 
@@ -390,16 +405,16 @@
1532
 
 
1533
 
     switch (size) {
1534
 
     case 1:
1535
 
-        val = virtio_config_readb(proxy->vdev, addr);
1536
 
+        val = virtio_config_readb(vdev, addr);
1537
 
         break;
1538
 
     case 2:
1539
 
-        val = virtio_config_readw(proxy->vdev, addr);
1540
 
+        val = virtio_config_readw(vdev, addr);
1541
 
         if (virtio_is_big_endian()) {
1542
 
             val = bswap16(val);
1543
 
         }
1544
 
         break;
1545
 
     case 4:
1546
 
-        val = virtio_config_readl(proxy->vdev, addr);
1547
 
+        val = virtio_config_readl(vdev, addr);
1548
 
         if (virtio_is_big_endian()) {
1549
 
             val = bswap32(val);
1550
 
         }
1551
 
@@ -413,6 +428,7 @@
1552
 
 {
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);
1558
 
         return;
1559
 
@@ -424,19 +440,19 @@
1560
 
      */
1561
 
     switch (size) {
1562
 
     case 1:
1563
 
-        virtio_config_writeb(proxy->vdev, addr, val);
1564
 
+        virtio_config_writeb(vdev, addr, val);
1565
 
         break;
1566
 
     case 2:
1567
 
         if (virtio_is_big_endian()) {
1568
 
             val = bswap16(val);
1569
 
         }
1570
 
-        virtio_config_writew(proxy->vdev, addr, val);
1571
 
+        virtio_config_writew(vdev, addr, val);
1572
 
         break;
1573
 
     case 4:
1574
 
         if (virtio_is_big_endian()) {
1575
 
             val = bswap32(val);
1576
 
         }
1577
 
-        virtio_config_writel(proxy->vdev, addr, val);
1578
 
+        virtio_config_writel(vdev, addr, val);
1579
 
         break;
1580
 
     }
1581
 
 }
1582
 
@@ -455,6 +471,7 @@
1583
 
                                 uint32_t val, int len)
1584
 
 {
1585
 
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
1586
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1587
 
 
1588
 
     pci_default_write_config(pci_dev, address, val, len);
1589
 
 
1590
 
@@ -462,8 +479,7 @@
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);
1597
 
     }
1598
 
 }
1599
 
 
1600
 
@@ -506,7 +522,8 @@
1601
 
                                  unsigned int vector)
1602
 
 {
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);
1608
 
     int ret;
1609
 
     ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, NULL, irqfd->virq);
1610
 
@@ -517,7 +534,8 @@
1611
 
                                       unsigned int queue_no,
1612
 
                                       unsigned int vector)
1613
 
 {
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];
1619
 
     int ret;
1620
 
@@ -529,7 +547,7 @@
1621
 
 static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
1622
 
 {
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;
1628
 
     int ret, queue_no;
1629
 
@@ -578,7 +596,7 @@
1630
 
 static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
1631
 
 {
1632
 
     PCIDevice *dev = &proxy->pci_dev;
1633
 
-    VirtIODevice *vdev = proxy->vdev;
1634
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1635
 
     unsigned int vector;
1636
 
     int queue_no;
1637
 
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
1638
 
@@ -606,8 +624,9 @@
1639
 
                                        unsigned int vector,
1640
 
                                        MSIMessage msg)
1641
 
 {
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);
1648
 
     VirtIOIRQFD *irqfd;
1649
 
     int ret = 0;
1650
 
@@ -626,10 +645,10 @@
1651
 
      * Otherwise, set it up now.
1652
 
      */
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);
1661
 
         }
1662
 
     } else {
1663
 
@@ -642,13 +661,14 @@
1664
 
                                              unsigned int queue_no,
1665
 
                                              unsigned int vector)
1666
 
 {
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);
1670
 
 
1671
 
     /* If guest supports masking, keep irqfd but mask it.
1672
 
      * Otherwise, clean it up now.
1673
 
      */ 
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);
1677
 
     } else {
1678
 
         kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
1679
 
     }
1680
 
@@ -658,7 +678,7 @@
1681
 
                                     MSIMessage msg)
1682
 
 {
1683
 
     VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
1684
 
-    VirtIODevice *vdev = proxy->vdev;
1685
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1686
 
     int ret, queue_no;
1687
 
 
1688
 
     for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) {
1689
 
@@ -688,7 +708,7 @@
1690
 
 static void virtio_pci_vector_mask(PCIDevice *dev, unsigned vector)
1691
 
 {
1692
 
     VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
1693
 
-    VirtIODevice *vdev = proxy->vdev;
1694
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1695
 
     int queue_no;
1696
 
 
1697
 
     for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) {
1698
 
@@ -707,7 +727,7 @@
1699
 
                                    unsigned int vector_end)
1700
 
 {
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);
1705
 
     int queue_no;
1706
 
     unsigned int vector;
1707
 
@@ -739,8 +759,9 @@
1708
 
                                          bool with_irqfd)
1709
 
 {
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);
1717
 
 
1718
 
     if (assign) {
1719
 
@@ -755,7 +776,7 @@
1720
 
     }
1721
 
 
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);
1725
 
     }
1726
 
 
1727
 
     return 0;
1728
 
@@ -770,7 +791,7 @@
1729
 
 static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign)
1730
 
 {
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);
1735
 
     int r, n;
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)
1739
 
 {
1740
 
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
1741
 
+    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
1742
 
 
1743
 
     if (running) {
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;
1750
 
         }
1751
 
@@ -943,8 +965,6 @@
1752
 
     uint8_t *config;
1753
 
     uint32_t size;
1754
 
 
1755
 
-    proxy->vdev = bus->vdev;
1756
 
-
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);
1762
 
 }
1763
 
 
1764
 
+static void virtio_pci_device_unplugged(DeviceState *d)
1765
 
+{
1766
 
+    PCIDevice *pci_dev = PCI_DEVICE(d);
1767
 
+    VirtIOPCIProxy *proxy = VIRTIO_PCI(d);
1768
 
+
1769
 
+    virtio_pci_stop_ioeventfd(proxy);
1770
 
+    msix_uninit_exclusive_bar(pci_dev);
1771
 
+}
1772
 
+
1773
 
 static int virtio_pci_init(PCIDevice *pci_dev)
1774
 
 {
1775
 
     VirtIOPCIProxy *dev = VIRTIO_PCI(pci_dev);
1776
 
@@ -996,9 +1025,7 @@
1777
 
 static void virtio_pci_exit(PCIDevice *pci_dev)
1778
 
 {
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);
1783
 
 }
1784
 
 
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;
1791
 
 }
1792
 
 
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
1798
 
@@ -82,7 +82,6 @@
1799
 
 
1800
 
 struct VirtIOPCIProxy {
1801
 
     PCIDevice pci_dev;
1802
 
-    VirtIODevice *vdev;
1803
 
     MemoryRegion bar;
1804
 
     uint32_t flags;
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);
1812
 
 }
1813
 
 
1814
 
-static int virtio_rng_device_init(VirtIODevice *vdev)
1815
 
+static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
1816
 
 {
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;
1822
 
 
1823
 
     if (!vrng->conf.period_ms > 0) {
1824
 
-        qerror_report(QERR_INVALID_PARAMETER_VALUE, "period",
1825
 
-                      "a positive number");
1826
 
-        return -1;
1827
 
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "period",
1828
 
+                  "a positive number");
1829
 
+        return;
1830
 
     }
1831
 
 
1832
 
     if (vrng->conf.rng == NULL) {
1833
 
         vrng->conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
1834
 
 
1835
 
-        object_property_add_child(OBJECT(qdev),
1836
 
+        object_property_add_child(OBJECT(dev),
1837
 
                                   "default-backend",
1838
 
                                   OBJECT(vrng->conf.default_backend),
1839
 
                                   NULL);
1840
 
 
1841
 
-        object_property_set_link(OBJECT(qdev),
1842
 
+        object_property_set_link(OBJECT(dev),
1843
 
                                  OBJECT(vrng->conf.default_backend),
1844
 
                                  "rng", NULL);
1845
 
     }
1846
 
@@ -162,15 +162,14 @@
1847
 
 
1848
 
     vrng->rng = vrng->conf.rng;
1849
 
     if (vrng->rng == NULL) {
1850
 
-        qerror_report(QERR_INVALID_PARAMETER_VALUE, "rng", "a valid object");
1851
 
-        return -1;
1852
 
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "rng", "a valid object");
1853
 
+        return;
1854
 
     }
1855
 
 
1856
 
     rng_backend_open(vrng->rng, &local_err);
1857
 
     if (local_err) {
1858
 
-        qerror_report_err(local_err);
1859
 
-        error_free(local_err);
1860
 
-        return -1;
1861
 
+        error_propagate(errp, local_err);
1862
 
+        return;
1863
 
     }
1864
 
 
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);
1869
 
 
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);
1873
 
-
1874
 
-    return 0;
1875
 
 }
1876
 
 
1877
 
-static int virtio_rng_device_exit(DeviceState *qdev)
1878
 
+static void virtio_rng_device_unrealize(DeviceState *dev, Error **errp)
1879
 
 {
1880
 
-    VirtIORNG *vrng = VIRTIO_RNG(qdev);
1881
 
-    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
1882
 
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
1883
 
+    VirtIORNG *vrng = VIRTIO_RNG(dev);
1884
 
 
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);
1890
 
-    return 0;
1891
 
 }
1892
 
 
1893
 
 static Property virtio_rng_properties[] = {
1894
 
@@ -211,10 +207,11 @@
1895
 
 {
1896
 
     DeviceClass *dc = DEVICE_CLASS(klass);
1897
 
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
1898
 
-    dc->exit = virtio_rng_device_exit;
1899
 
+
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;
1906
 
 }
1907
 
 
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 @@
1913
 
     }
1914
 
 }
1915
 
 
1916
 
-static int virtio_device_init(DeviceState *qdev)
1917
 
+static void virtio_device_realize(DeviceState *dev, Error **errp)
1918
 
 {
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) {
1923
 
-        return -1;
1924
 
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
1925
 
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
1926
 
+    Error *err = NULL;
1927
 
+
1928
 
+    if (vdc->realize != NULL) {
1929
 
+        vdc->realize(dev, &err);
1930
 
+        if (err != NULL) {
1931
 
+            error_propagate(errp, err);
1932
 
+            return;
1933
 
+        }
1934
 
     }
1935
 
-    virtio_bus_plug_device(vdev);
1936
 
-    return 0;
1937
 
+    virtio_bus_device_plugged(vdev);
1938
 
 }
1939
 
 
1940
 
-static int virtio_device_exit(DeviceState *qdev)
1941
 
+static void virtio_device_unrealize(DeviceState *dev, Error **errp)
1942
 
 {
1943
 
-    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
1944
 
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
1945
 
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
1946
 
+    Error *err = NULL;
1947
 
+
1948
 
+    virtio_bus_device_unplugged(vdev);
1949
 
+
1950
 
+    if (vdc->unrealize != NULL) {
1951
 
+        vdc->unrealize(dev, &err);
1952
 
+        if (err != NULL) {
1953
 
+            error_propagate(errp, err);
1954
 
+            return;
1955
 
+        }
1956
 
+    }
1957
 
 
1958
 
     if (vdev->bus_name) {
1959
 
         g_free(vdev->bus_name);
1960
 
         vdev->bus_name = NULL;
1961
 
     }
1962
 
-    return 0;
1963
 
 }
1964
 
 
1965
 
 static void virtio_device_class_init(ObjectClass *klass, void *data)
1966
 
 {
1967
 
     /* Set the default value here. */
1968
 
     DeviceClass *dc = DEVICE_CLASS(klass);
1969
 
-    dc->init = virtio_device_init;
1970
 
-    dc->exit = virtio_device_exit;
1971
 
+
1972
 
+    dc->realize = virtio_device_realize;
1973
 
+    dc->unrealize = virtio_device_unrealize;
1974
 
     dc->bus_type = TYPE_VIRTIO_BUS;
1975
 
 }
1976
 
 
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
1981
 
@@ -61,7 +61,7 @@
1982
 
      * transport independent exit function.
1983
 
      * This is called by virtio-bus just before the device is unplugged.
1984
 
      */
1985
 
-    void (*device_unplug)(DeviceState *d);
1986
 
+    void (*device_unplugged)(DeviceState *d);
1987
 
     /*
1988
 
      * Does the transport have variable vring alignment?
1989
 
      * (ie can it ever call virtio_queue_set_align()?)
1990
 
@@ -72,15 +72,11 @@
1991
 
 
1992
 
 struct VirtioBusState {
1993
 
     BusState parent_obj;
1994
 
-    /*
1995
 
-     * Only one VirtIODevice can be plugged on the bus.
1996
 
-     */
1997
 
-    VirtIODevice *vdev;
1998
 
 };
1999
 
 
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. */
2008
 
@@ -98,4 +94,16 @@
2009
 
 /* Set config of the plugged device. */
2010
 
 void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config);
2011
 
 
2012
 
+static inline VirtIODevice *virtio_bus_get_device(VirtioBusState *bus)
2013
 
+{
2014
 
+    BusState *qbus = &bus->parent_obj;
2015
 
+    BusChild *kid = QTAILQ_FIRST(&qbus->children);
2016
 
+    DeviceState *qdev = kid ? kid->child : NULL;
2017
 
+
2018
 
+    /* This is used on the data path, the cast is guaranteed
2019
 
+     * to succeed by the qdev machinery.
2020
 
+     */
2021
 
+    return (VirtIODevice *)qdev;
2022
 
+}
2023
 
+
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
2029
 
@@ -18,6 +18,8 @@
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)
2035
 
 
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
2042
 
@@ -186,7 +186,7 @@
2043
 
     DEFINE_PROP_BIT("param_change", _state, _feature_field,                    \
2044
 
                                             VIRTIO_SCSI_F_CHANGE, true)
2045
 
 
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);
2050
 
 
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 @@
2057
 
 };
2058
 
 
2059
 
 typedef struct VirtioDeviceClass {
2060
 
-    /* This is what a VirtioDevice must implement */
2061
 
+    /*< private >*/
2062
 
     DeviceClass parent;
2063
 
-    int (*init)(VirtIODevice *vdev);
2064
 
+    /*< public >*/
2065
 
+
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
2076
 
@@ -32,10 +32,8 @@
2077
 
                    "}}");
2078
 
     g_assert(response);
2079
 
     error = qdict_get_qdict(response, "error");
2080
 
-    g_assert(!strcmp(qdict_get_try_str(error, "class") ?: "",
2081
 
-                     "GenericError"));
2082
 
     g_assert(!strcmp(qdict_get_try_str(error, "desc") ?: "",
2083
 
-                     "Device initialization failed."));
2084
 
+                     "Device needs media, but drive is empty"));
2085
 
     QDECREF(response);
2086
 
 
2087
 
     /* Delete the drive */