diff options
author | Amit Shah <amit.shah@redhat.com> | 2011-12-22 06:28:34 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-01-12 00:14:46 -0500 |
commit | be91c33dd15eff6b0dffc60cee4c8042e75493d2 (patch) | |
tree | 0e7738cfa3a30e00ef4ac7a6d87ad5f50e469dc1 /drivers | |
parent | 0741bcb5584f9e2390ae6261573c4de8314999f2 (diff) |
virtio: balloon: Move vq initialization into separate function
The probe and PM restore functions will share this code.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/virtio/virtio_balloon.c | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 0a6425aadf95..3368cb6ef193 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c | |||
@@ -275,32 +275,21 @@ static int balloon(void *_vballoon) | |||
275 | return 0; | 275 | return 0; |
276 | } | 276 | } |
277 | 277 | ||
278 | static int virtballoon_probe(struct virtio_device *vdev) | 278 | static int init_vqs(struct virtio_balloon *vb) |
279 | { | 279 | { |
280 | struct virtio_balloon *vb; | ||
281 | struct virtqueue *vqs[3]; | 280 | struct virtqueue *vqs[3]; |
282 | vq_callback_t *callbacks[] = { balloon_ack, balloon_ack, stats_request }; | 281 | vq_callback_t *callbacks[] = { balloon_ack, balloon_ack, stats_request }; |
283 | const char *names[] = { "inflate", "deflate", "stats" }; | 282 | const char *names[] = { "inflate", "deflate", "stats" }; |
284 | int err, nvqs; | 283 | int err, nvqs; |
285 | 284 | ||
286 | vdev->priv = vb = kmalloc(sizeof(*vb), GFP_KERNEL); | 285 | /* |
287 | if (!vb) { | 286 | * We expect two virtqueues: inflate and deflate, and |
288 | err = -ENOMEM; | 287 | * optionally stat. |
289 | goto out; | 288 | */ |
290 | } | ||
291 | |||
292 | INIT_LIST_HEAD(&vb->pages); | ||
293 | vb->num_pages = 0; | ||
294 | init_waitqueue_head(&vb->config_change); | ||
295 | vb->vdev = vdev; | ||
296 | vb->need_stats_update = 0; | ||
297 | |||
298 | /* We expect two virtqueues: inflate and deflate, | ||
299 | * and optionally stat. */ | ||
300 | nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 : 2; | 289 | nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 : 2; |
301 | err = vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names); | 290 | err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names); |
302 | if (err) | 291 | if (err) |
303 | goto out_free_vb; | 292 | return err; |
304 | 293 | ||
305 | vb->inflate_vq = vqs[0]; | 294 | vb->inflate_vq = vqs[0]; |
306 | vb->deflate_vq = vqs[1]; | 295 | vb->deflate_vq = vqs[1]; |
@@ -318,6 +307,29 @@ static int virtballoon_probe(struct virtio_device *vdev) | |||
318 | BUG(); | 307 | BUG(); |
319 | virtqueue_kick(vb->stats_vq); | 308 | virtqueue_kick(vb->stats_vq); |
320 | } | 309 | } |
310 | return 0; | ||
311 | } | ||
312 | |||
313 | static int virtballoon_probe(struct virtio_device *vdev) | ||
314 | { | ||
315 | struct virtio_balloon *vb; | ||
316 | int err; | ||
317 | |||
318 | vdev->priv = vb = kmalloc(sizeof(*vb), GFP_KERNEL); | ||
319 | if (!vb) { | ||
320 | err = -ENOMEM; | ||
321 | goto out; | ||
322 | } | ||
323 | |||
324 | INIT_LIST_HEAD(&vb->pages); | ||
325 | vb->num_pages = 0; | ||
326 | init_waitqueue_head(&vb->config_change); | ||
327 | vb->vdev = vdev; | ||
328 | vb->need_stats_update = 0; | ||
329 | |||
330 | err = init_vqs(vb); | ||
331 | if (err) | ||
332 | goto out_free_vb; | ||
321 | 333 | ||
322 | vb->thread = kthread_run(balloon, vb, "vballoon"); | 334 | vb->thread = kthread_run(balloon, vb, "vballoon"); |
323 | if (IS_ERR(vb->thread)) { | 335 | if (IS_ERR(vb->thread)) { |