Commit be91c33d authored by Amit Shah's avatar Amit Shah Committed by Rusty Russell

virtio: balloon: Move vq initialization into separate function

The probe and PM restore functions will share this code.
Signed-off-by: default avatarAmit Shah <amit.shah@redhat.com>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 0741bcb5
...@@ -275,32 +275,21 @@ static int balloon(void *_vballoon) ...@@ -275,32 +275,21 @@ static int balloon(void *_vballoon)
return 0; return 0;
} }
static int virtballoon_probe(struct virtio_device *vdev) static int init_vqs(struct virtio_balloon *vb)
{ {
struct virtio_balloon *vb;
struct virtqueue *vqs[3]; struct virtqueue *vqs[3];
vq_callback_t *callbacks[] = { balloon_ack, balloon_ack, stats_request }; vq_callback_t *callbacks[] = { balloon_ack, balloon_ack, stats_request };
const char *names[] = { "inflate", "deflate", "stats" }; const char *names[] = { "inflate", "deflate", "stats" };
int err, nvqs; int err, nvqs;
vdev->priv = vb = kmalloc(sizeof(*vb), GFP_KERNEL); /*
if (!vb) { * We expect two virtqueues: inflate and deflate, and
err = -ENOMEM; * optionally stat.
goto out; */
}
INIT_LIST_HEAD(&vb->pages);
vb->num_pages = 0;
init_waitqueue_head(&vb->config_change);
vb->vdev = vdev;
vb->need_stats_update = 0;
/* We expect two virtqueues: inflate and deflate,
* and optionally stat. */
nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 : 2; nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 : 2;
err = vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names); err = vb->vdev->config->find_vqs(vb->vdev, nvqs, vqs, callbacks, names);
if (err) if (err)
goto out_free_vb; return err;
vb->inflate_vq = vqs[0]; vb->inflate_vq = vqs[0];
vb->deflate_vq = vqs[1]; vb->deflate_vq = vqs[1];
...@@ -318,6 +307,29 @@ static int virtballoon_probe(struct virtio_device *vdev) ...@@ -318,6 +307,29 @@ static int virtballoon_probe(struct virtio_device *vdev)
BUG(); BUG();
virtqueue_kick(vb->stats_vq); virtqueue_kick(vb->stats_vq);
} }
return 0;
}
static int virtballoon_probe(struct virtio_device *vdev)
{
struct virtio_balloon *vb;
int err;
vdev->priv = vb = kmalloc(sizeof(*vb), GFP_KERNEL);
if (!vb) {
err = -ENOMEM;
goto out;
}
INIT_LIST_HEAD(&vb->pages);
vb->num_pages = 0;
init_waitqueue_head(&vb->config_change);
vb->vdev = vdev;
vb->need_stats_update = 0;
err = init_vqs(vb);
if (err)
goto out_free_vb;
vb->thread = kthread_run(balloon, vb, "vballoon"); vb->thread = kthread_run(balloon, vb, "vballoon");
if (IS_ERR(vb->thread)) { if (IS_ERR(vb->thread)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment